![](/img/trans.png)
[英]Pandas returns error: 'Series' objects are mutable, thus they cannot be hashed
[英]Pandas loc error: 'Series' objects are mutable, thus they cannot be hashed
嘿伙計們,我需要一些幫助來解決處理 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)
我在熊貓數據框中加載了一個 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)
現在我想刪除數據框中的所有列,在“Z”列中沒有值 z。 我收到錯誤消息:“TypeError:'Series' 對象是可變的,因此它們不能被散列”。 我不知道該怎么做,因為我如何看待它與熊貓紀錄片中的完全相同。https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.loc.html:
df.loc[df['shield'] > 6]
max_speed shield
sidewinder 7 8
拜托我需要你的幫忙。
先謝謝了!
你也可以用 lambda 表達式來做到這一點:
df = df[lambda x: x['Z'] == z]
您可以在df.loc
使用方括號:
df = df.loc[df['Z'] == z]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.