Delete Column in Python with pandas
In Python, you can use the pandas library to delete a column of data. Here is a simple example:
import pandas as pd
# 创建一个DataFrame
data = {'A': [1, 2, 3, 4],
'B': [5, 6, 7, 8]}
df = pd.DataFrame(data)
# 删除列B
df.drop('B', axis=1, inplace=True)
print(df)
When running the code above, the output result will be:
A
0 1
1 2
2 3
3 4
In this example, we used the drop method to remove column B. The parameter axis=1 indicates that we are deleting a column of data, and inplace=True means that we are making the modification directly on the original DataFrame.