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.
–
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.