pandas 只取某几列
可以使用[]操作符来只取某几列,例如:
import pandas as pd
# 创建一个DataFrame
data = {'col1': [1, 2, 3],
'col2': [4, 5, 6],
'col3': [7, 8, 9]}
df = pd.DataFrame(data)
# 只取col1和col3列
df_subset = df[['col1', 'col3']]
print(df_subset)
输出结果为:
col1 col3
0 1 7
1 2 8
2 3 9
原文地址: http://www.cveoy.top/t/topic/iYMQ 著作权归作者所有。请勿转载和采集!