How do you delete a column of data from a table in Pyth…
You can use the drop() function from the pandas library to delete a column of data in a table. Here is an example code:
import pandas as pd
# 创建一个DataFrame示例
data = {'A': [1, 2, 3],
'B': [4, 5, 6],
'C': [7, 8, 9]}
df = pd.DataFrame(data)
# 删除列B
df = df.drop('B', axis=1)
print(df)
The output will be:
A C
0 1 7
1 2 8
2 3 9
In this example, the drop() function was used to remove column B. The parameter axis=1 specifies that columns should be deleted, while axis=0 specifies that rows should be deleted.