简体   繁体   English

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

[英]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.

相关问题 Pandas 返回错误:“系列”对象是可变的,因此它们不能被散列 - Pandas returns error: 'Series' objects are mutable, thus they cannot be hashed 访问loc中的列值会导致错误“'系列'对象是可变的,因此无法进行哈希处理” - Accessing column value within loc gives error “'Series' objects are mutable, thus they cannot be hashed” 系列对象是可变的,因此它们不能在 Python pandas 数据帧上散列 - Series objects are mutable, thus they cannot be hashed on Python pandas dataframe Python 和 Pandas:“系列”对象是可变的,因此它们不能被散列 - Python & Pandas: 'Series' objects are mutable, thus they cannot be hashed pandas Python Series对象是可变的,因此它们不能在查询方法中进行散列 - pandas Python Series objects are mutable, thus they cannot be hashed in query method 'Series'对象是可变的,因此它们不能在调用to_csv时出现散列错误 - 'Series' objects are mutable, thus they cannot be hashed error calling to_csv 键控错误:“系列”对象是可变的,因此它们不能被散列 - Keying Error: 'Series' objects are mutable, thus they cannot be hashed 在 dataframe 类型错误中出现错误:“系列”对象是可变的,因此无法对其进行哈希处理 - Getting error in dataframe typeError: 'Series' objects are mutable, thus they cannot be hashed 类型错误:“系列”对象是可变的,因此它们不能被散列 - TypeError: 'Series' objects are mutable, thus they cannot be hashed Python:“系列”对象是可变的,因此它们不能被散列 - Python : 'Series' objects are mutable, thus they cannot be hashed
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM