drop
时间: 2023-07-25 20:16:14 浏览: 103
In programming, "drop" usually refers to the action of removing something, such as dropping a column or a row from a dataframe. Here is an example of how to drop a column from a dataframe in Python using the Pandas library:
```
import pandas as pd
# create a sample dataframe
df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6], 'C': [7, 8, 9]})
# drop a column by specifying the column name and axis=1
df = df.drop('C', axis=1)
# print the resulting dataframe
print(df)
```
This will output the following dataframe with the 'C' column dropped:
```
A B
0 1 4
1 2 5
2 3 6
```
Here, we use the drop() method and pass the name of the column we want to drop as the first argument. We also specify axis=1 to indicate that we want to drop a column (as opposed to a row, which would be axis=0). Finally, we assign the resulting dataframe back to the variable df to update it with the dropped column.
阅读全文