我正在尝试执行以下代码:
data = pd.read_csv('statistic.csv', parse_dates=True, index_col=['DATE'],
low_memory=False, nrows=5000000)
data_extracted = data.groupby(['DATE','ARTICLENO'])['QUANTITY'].sum().unstack()
data_extracted = data_extracted.loc['2015-01-01' : '2015-12-31']
data_extracted = data_extracted.replace([np.inf, -np.inf],
np.nan).fillna(0.0001)
data_pct_change = data_extracted.pct_change(axis=0).replace([np.inf, -
np.inf], np.nan).fillna(0)
data_pct_change.drop([col for col, val in data_pct_change.sum() if val == 0
], axis=1, inplace=True)
执行此操作时,出现TypeError:/的不支持的操作数类型:'str'和'str'。
当我尝试执行data_extracted['ARTICLENO] = data_extracted['ARTICLENO'].astype(float)
时,出现相同的错误。
当我打印data_extracted.dtypes时,它们都是浮动的。
有人可以帮我吗?
答案 0 :(得分:1)
我认为需要将非数值转换为NaN
:
data_extracted['ARTICLENO'] = pd.to_numeric(data_extracted['ARTICLENO'], errors='coerce')