小编Sam*_* K.的帖子

Pandas loc 错误:“系列”对象是可变的,因此它们不能被散列

嘿伙计们,我需要一些帮助来解决处理 Panda 数据帧的问题。这是代码:

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)
Run Code Online (Sandbox Code Playgroud)

我在熊猫数据框中加载了一个 Excel 表。现在经过一些预处理后,数据框采用以下形式:

          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)
Run Code Online (Sandbox Code Playgroud)

现在我想删除数据框中的所有列,在“Z”列中没有值 z。我收到错误消息:“TypeError:'Series' 对象是可变的,因此它们不能被散列”。我不知道该怎么做,因为我如何看待它与熊猫纪录片中的完全相同。https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.loc.html:

df.loc[df['shield'] > 6] …
Run Code Online (Sandbox Code Playgroud)

python typeerror loc dataframe pandas

5
推荐指数
2
解决办法
6253
查看次数

标签 统计

dataframe ×1

loc ×1

pandas ×1

python ×1

typeerror ×1