lig*_*nin 4 python slice pandas
我有大于100列的数据框.我想选择0~32和#83列.看起来1切片可以正常使用下面的代码.
df_new = df[df.columns[0:32]]
Run Code Online (Sandbox Code Playgroud)
但它不适用于下面的2个切片代码.我该如何解决这个问题?
df_new = df[df.columns[0:32, 83]]
Run Code Online (Sandbox Code Playgroud)
np.r_结合使用索引器iloc,如下所示:
df.iloc[:, np.r_[0:32, 83]]
Run Code Online (Sandbox Code Playgroud)
np.r_[0:32, 83]
array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 83])
Run Code Online (Sandbox Code Playgroud)