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.