[英]Pandas loc error: 'Series' objects are mutable, thus they cannot be hashed
Hey guys i need some help with a Problem in handling Panda dataframes.嘿伙计们,我需要一些帮助来解决处理 Panda 数据帧的问题。 Here is the Code:
这是代码:
df.drop(df.index[0], inplace=True)
df.columns = ['Mic. No.', 'X', 'Y', 'Z', 'Re. Pre.', 'Im. Pre.']
df['Pre'] = df['Re. Pre.'] + df['Im. Pre.'] * 1j
df.drop(['Mic. No.', 'Re. Pre.', 'Im. Pre.'], axis=1, inplace=True)
if z != 0:
df = df.loc(df['Z'] == z)
i loaded an excel sheet in a panda dataframe.我在熊猫数据框中加载了一个 Excel 表。 Now after some preprocessing the dataframe is in the following form:
现在经过一些预处理后,数据框采用以下形式:
X Y Z Pre
1 0.16 0.16 0.05 (1.0048704-0.51310315j)
2 0.16 -0.16 0.05 (0.24814222-1.6094971j)
3 -0.16 0.16 0.05 (0.24815122-1.6094059j)
4 -0.16 -0.16 0.05 (1.0048704-0.51310315j)
5 -0.154993 0.154993 0.05 (-0.13939651-1.7231593j)
now i want to delete all columns in the dataframe witch dont have the Value z in the column "Z".现在我想删除数据框中的所有列,在“Z”列中没有值 z。 I get the error: "TypeError:'Series' objects are mutable, thus they cannot be hashed".
我收到错误消息:“TypeError:'Series' 对象是可变的,因此它们不能被散列”。 I dont know what to do because how i see it its exacly the same like in the pandas documentary.https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.loc.html :
我不知道该怎么做,因为我如何看待它与熊猫纪录片中的完全相同。https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.loc.html:
df.loc[df['shield'] > 6]
max_speed shield
sidewinder 7 8
please i need your help.拜托我需要你的帮忙。
Thanks ahead!先谢谢了!
你也可以用 lambda 表达式来做到这一点:
df = df[lambda x: x['Z'] == z]
您可以在df.loc
使用方括号:
df = df.loc[df['Z'] == z]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.