您可以先调整形状
stack,然后转换为
tuples:
tups = [tuple(x) for x in df.stack().reset_index().values.tolist()]
另一个类似的解决方案是创建3个级别
MultiIndex:
tups = df.stack().to_frame().set_index(0, append=True).index.tolist()
或
zip3分别
array以S
numpy.repeat,
numpy.tile和
ravel:
a = np.repeat(df.index, len(df.columns))b = np.tile(df.columns, len(df))c = df.values.ravel()tups = list(zip(a,b,c))



