简体   繁体   English

如何解决以下错误 - TypeError: unsupported operand type(s) for -: 'int' and 'str'

[英]how do I resolve the following error - TypeError: unsupported operand type(s) for -: 'int' and 'str'

I am getting the following error in my code.我的代码中出现以下错误。 confirmed_India, recovered_India, deaths_India are list of table that includes a predefined dataset for corona cases.Code: confirmed_India、recovered_India、deaths_India 是表的列表,其中包含预定义的电晕病例数据集。代码:

confirmed_India_ts = confirmed_df[confirmed_df['Country/Region'] == "India"]

confirmed_India_ts = confirmed_India_ts.drop(
['Lat','Long','Country/Region','Province/State'],axis=1).reset_index(drop=True).sum()

deaths_India_ts = deaths_df[deaths_df['Country/Region'] == "India"]

confirmed_India_ts = deaths_India_ts.drop(
['Lat','Long','Country/Region','Province/State'],axis=1).reset_index(drop=True).sum()

recovered_India_ts = recovered_df[recovered_df['Country/Region'] == "India"]

recovered_India_ts = deaths_India_ts.drop(
['Lat','Long','Country/Region','Province/State'],axis=1).reset_index(drop=True).sum()

active_India_ts = pd.Series(
    data = np.array(
            
[(x1 - x2 - x3) for (x1, x2, x3) in zip(
                confirmed_India_ts.values, deaths_India_ts.values, 

recovered_India_ts.values)
               
 ]
                
        ),
        index = confirmed_India_ts.index
)





error:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-54-68268b5b4ce7> in <module>
 14         data = np.array(
 15                 [(x1 - x2 - x3) for (x1, x2, x3) in zip(
---> 16                     confirmed_India_ts.values, deaths_India_ts.values,      recovered_India_ts.values)
 17                     ]
 18 

 <ipython-input-54-68268b5b4ce7> in <listcomp>(.0)
 13 active_India_ts = pd.Series(
 14         data = np.array(
---> 15                 [(x1 - x2 - x3) for (x1, x2, x3) in zip(
 16                     confirmed_India_ts.values, deaths_India_ts.values, recovered_India_ts.values)
 17                     ]

TypeError: unsupported operand type(s) for -: 'int' and 'str' TypeError: 不支持的操作数类型 -: 'int' 和 'str'

This error is suggesting that you are trying to subtract Integer type and String type.此错误提示您正在尝试减去 Integer 类型和 String 类型。 So I suggest you check your Data type of each of your x1,2,3 RIGHT before doing that (x1 - x2 - x3) Operation.因此,我建议您在执行 (x1 - x2 - x3) 操作之前检查每个 x1、2、3 RIGHT 的数据类型。 Maybe you messed up one of the types during preprocessing.也许您在预处理过程中弄乱了其中一种类型。 Eg.例如。 x1 is Int type, but x2 is a string. x1 是 Int 类型,而 x2 是字符串。

Please provide more info so I maybe able to help you.请提供更多信息,以便我可以帮助你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何解决 typeError:heroku 在 django 应用程序中 /: &#39;str&#39; 和 &#39;str&#39; 的不支持的操作数类型? - How do I resolve typeError: unsupported operand type(s) for /: 'str' and 'str' in django app by heroku? 如何修复 TypeError: +: 'int' 和 'str' 不支持的操作数类型 - How do I fix TypeError: unsupported operand type(s) for +: 'int' and 'str' 如何解决:TypeError:+ 的不支持的操作数类型:“int”和“list” - How do I resolve: TypeError: unsupported operand type(s) for +: 'int' and 'list' typeerror 不支持 / &#39;str&#39; 和 &#39;int&#39; 的操作数类型 - typeerror unsupported operand type(s) for / 'str' and 'int' TypeError:-:“ str”和“ int”的不受支持的操作数类型 - TypeError:unsupported operand type(s) for -: 'str' and 'int' + 不支持的操作数类型:“int”和“str”[TypeError] - unsupported operand type(s) for +: 'int' and 'str' [TypeError] TypeError: 不支持的操作数类型 -: 'str' 和 'int' - TypeError: unsupported operand type(s) for -: 'str' and 'int' 类型错误:-= 不支持的操作数类型:'int' 和 'str' - TypeError: unsupported operand type(s) for -=: 'int' and 'str' TypeError:|:“ int”和“ str”不支持的操作数类型 - TypeError: unsupported operand type(s) for |: 'int' and 'str' TypeError:/:&#39;str&#39;和&#39;int&#39;的不支持的操作数类型 - TypeError: unsupported operand type(s) for /: 'str' and 'int'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM