是否有人知道如何为列合并for循环,但从任何列开始?(本方案的第三个方案)
让我们说,这是dataframe:
spice smice skice bike dike mike
1 23 35 34 34 56
135 34 23 21 56 34
231 12 67 21 62 75我想在skice,自行车,堤坝,和mike (只有)中迭代。
发布于 2018-07-18 18:03:01
由于df.columns提供了列的列表,所以您可以在下面执行并从第3列名进行迭代。
for col in df.columns[2:]:
#print(df[col].unique())发布于 2018-07-18 18:14:04
如果列不是连续的,则更一般的解决方案:
l = ['skice', 'bike', 'dike','mike']
cols = df.columns.intersection(l)
for col in cols:
print (col)https://stackoverflow.com/questions/51408351
复制相似问题