要?jiǎng)h除表中的一列數(shù)據(jù),可以使用pandas庫中的drop()函數(shù)。下面是一個(gè)示例代碼:
import pandas as pd
# 創(chuàng)建一個(gè)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)
輸出結(jié)果將是:
A C
0 1 7
1 2 8
2 3 9
在這個(gè)示例中,使用drop()函數(shù)刪除了列B,參數(shù)axis=1
表示刪除列,axis=0
表示刪除行。