【发布时间】:2020-11-23 21:59:38
【问题描述】:
在给定的数据框上,我正在根据来自不同列和另一个数据框的值创建一个新列。
创建新列的代码:
df['normalized_value'] = df.apply(lambda x:
x['value'] / rates_df.loc[rates_df['date'] == x['date'], 'EUR']
if
x['currency'] != 'EUR'
else
x['value'],
axis=1)
列创建后如下所示:
0 45500
1 32500
2 25000
3 33000
5 19000
...
61790 60000
61791 57000
61792 50999
61793 66500
61794 67000
Name: normalized_value, Length: 59951, dtype: object
然后我尝试使用以下代码将其转换为浮点类型:
df['normalized_value'] = pd.to_numeric(df['normalized_price'])
返回如下错误:
TypeError: 'Series' objects are mutable, thus they cannot be hashed
我在这里做错了什么?
【问题讨论】:
-
请在apply调用后告诉我们
df['normalized_price']中的内容