我需要一些帮助来解决处理 pandas DataFrame 的问题。这是代码:
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)
我在 panda 数据框中加载了 Excel 工作表。现在,经过一些预处理后,DataFrame 的形式如下:
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)
现在我想删除 DataFrame 中“Z”列中没有值 z 的所有列。我收到错误:“TypeError:‘Series’对象是可变的,因此无法对它们进行哈希处理”。我不知道该怎么做,因为我所看到的与 pandas 文档中的完全相同。https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.loc.html
df.loc[df['shield'] > 6]
max_speed shield
sidewinder 7 8
元芳怎么了
慕森卡
相关分类