如何删除Pandas中的行?

2024-05-14 22:11:18 发布

您现在位置:Python中文网/ 问答频道 /正文

从数据框中删除特定行时遇到问题。我首先收集了我想要删除的行,并将它们存储在一个变量中,然后试图从df中删除它们,但我遇到了麻烦。有人能指引我吗

n = ['NES', 'SNES', 'N64', '2600', 'PSV', 'SAT', 'WS', 'NG', 'TG16', 'GG', 'PCFX', '3DO', 'SCD', 'GB']
df_drop = df[df['platform'].isin(n)]
df = df.drop(df_drop, axis=0)
KeyError                                  Traceback (most recent call last)
<ipython-input-8-80322bccee93> in <module>
      2 n = ['NES', 'SNES', 'N64', '2600', 'PSV', 'SAT', 'WS', 'NG', 'TG16', 'GG', 'PCFX', '3DO', 'SCD', 'GB']
      3 df_drop = df[df['platform'].isin(n)]
----> 4 df = df.drop(df_drop, axis=0)


----
KeyError: "['name' 'platform' 'year_of_release' 'genre' 'na_sales' 'eu_sales'\n 'jp_sales' 'other_sales' 'critic_score' 'user_score' 'rating'\n 'total_sales'] not found in axis"

Tags: dfwsngsatdropplatformsalesgg

热门问题