pandas中drop的使用
时间: 2023-10-30 21:36:55 浏览: 63
Pandas基础之drop函数的使用
Sure, I can help you with that! The drop() function in pandas is used to remove rows or columns from a DataFrame based on their labels or indexes. You can specify the labels/ indexes of the rows or columns that you want to remove as arguments to the drop() function. Alternatively, you can also drop rows or columns based on conditions using boolean indexing. For example:
To drop a single row with label 'A' from a DataFrame df:
df.drop('A', axis=0, inplace=True)
To drop multiple rows with labels 'A' and 'B':
df.drop(['A', 'B'], axis=0, inplace=True)
To drop a single column with label 'col1':
df.drop('col1', axis=1, inplace=True)
To drop multiple columns with labels 'col1' and 'col2':
df.drop(['col1', 'col2'], axis=1, inplace=True)
Hope this helps!
阅读全文