如何解决以下错误-TypeError:-不支持的操作数类型:'int'和'str'

问题描述

我的代码中出现以下错误。 Confirmed_India,recovery_India,deathes_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',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',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,x3) in zip(
---> 16                     confirmed_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,x3) in zip(
 16                     confirmed_India_ts.values,recovered_India_ts.values)
 17                     ]

TypeError:--'int'和'str'的不受支持的操作数类型

解决方法

此错误表明您尝试将Integer类型和String类型相减。因此,我建议您在执行(x1-x2-x3)操作之前检查每个x1,2,3 RIGHT的数据类型。也许您在预处理过程中弄乱了其中一种类型。例如。 x1是Int类型,但x2是字符串。

请提供更多信息,以便我可能为您提供帮助。