Y6=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]
Y6=pd.DataFrame(data=Y6)
for i in Y6:
df[i]=Y6.iloc[i:i+1]
print(df[2])
所需的输出-
df[1]=[1,2]
df[2]=[3,4]
我想将其分为10个数据帧,每个数据帧中包含2个组件。
答案 0 :(得分:0)
您只想要每两个值的数据框?
我仍然对您要寻找的东西感到困惑:
dfs = list()
for x in range(0, len(Y6), 2):
df = Y6.iloc[x:x+2].T
df.columns= ['one', 'two']
dfs.append(df)
for df in dfs:
print(df)
print()
结果是10个数据帧,每个数据帧包含一行,每个数据帧包含原始df中的2个项目:
one two
0 1 2
one two
0 3 4
one two
0 5 6
one two
0 7 8
one two
0 9 10
one two
0 11 12
one two
0 13 14
one two
0 15 16
one two
0 17 18
one two
0 19 20