【发布时间】:2021-07-08 09:15:59
【问题描述】:
假设我有这个数据框:
df = pd.DataFrame({'a' : (1, 2, 3),
'b' : (1, 2, 3),
'c' : ("one", "two", "three"),
'd' : (4, 5, 6),
'e' : (4, 5, 6),
'f' : (7, 8, 9),
'g' : (7, 8, 9),
'h' : (7, 8, 9)})
我正在尝试选择第一、第三和第五,直到最后一列。期望的输出是:
a c e f g h
0 1 one 4 7 7 8
1 2 two 5 8 7 8
2 3 three 6 9 9 9
如何使用整数选择多个不连续的列?我尝试了以下方法:
df.iloc[,[0, 3, 5:]]
df.loc[,[0, 3, 5:]]
df.iloc[,[0, 3, 5:len(df.columns)]]
df.loc[,[0, 3, 5:len(df.columns)]]
df.iloc[,[0 + 3 + 5:]]
df.loc[,[0 + 3 + 5:]]
df.iloc[,[0 + 3 + 5:len(df.columns)]]
df.loc[,[0 + 3 + 5:len(df.columns)]]
没有成功
请指教
【问题讨论】: