添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
豪情万千的豆腐  ·  python ...·  2 天前    · 
爱看书的核桃  ·  python ...·  2 天前    · 
安静的香菇  ·  Pybel转换分子文件格式·  7 小时前    · 
失落的炒饭  ·  CI/CD components | GitLab·  6 月前    · 
有胆有识的勺子  ·  微软.NET Framework ...·  1 年前    · 
慈祥的黄瓜  ·  XMLHttpRequest ...·  2 年前    · 
玩足球的包子  ·  sql - How to query to ...·  2 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I have a large file that I'm trying to reduce using dataframe.drop Here's my code:

probe_df = pd.read_csv(csv_file,header = 9233, nrows = 4608)
# Get rid of stuff
c_to_drop = 'Unnamed: ' + str(count_tp+1)
probe_df = probe_df.set_index("Chamber ID").drop(c_to_drop,1)

When I ran this, I got this error message:

probe_df = probe_df.set_index("Chamber ID").drop(c_to_drop,1)
TypeError: DataFrame.drop() takes from 1 to 2 positional arguments but 3 were given

I don't understand why I got the error and how to fix it. Please help!

I'm a newbie and I tried looking online for a solution but I'm still quite new and didn't see anything that matched my issue exactly.

assuming the 1 is intended to be axis, try doing probe_df.set_index("Chamber ID").drop(c_to_drop,axis=1). – Shorn Jun 6 at 2:26

According to the pandas documentation, the source for drop would be

DataFrame.drop(labels=None, *, axis=0, index=None, columns=None, level=None, inplace=False, errors='raise')

The * represents the end of allowed positional arguments. This indicates that the positional arguments would be labels, and for python's error message this would likely be from the self positional argument that is not directly shown as it is implicitly supplied.

Therefore, doing probe_df = probe_df.set_index("Chamber ID").drop(c_to_drop,1) would be feeding 2 positional arguments into a function which only takes 1 (not including self).

By changing it to probe_df.set_index("Chamber ID").drop(c_to_drop, axis=1), we convert the 1 from a positional argument to a keyword argument as required by the function.

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.