我有三个列表填充了数据,我想连接它们来创建一个数据帧
type of data_activationsLV : list
type of data_activationsF : list
type of data_activationsPC : list
三个列表的数据结构:
^{pr2}$。。在
我把它们转换成系列,然后把它们组合起来:
df15LV = pd.Series(data_activationsLV)
df15F = pd.Series(data_activationsF)
df15PC = pd.Series(data_activationsPC)
dfnew2=pd.concat([df15LV,df15F,df15PC], ignore_index=True, axis=1)
这里我有一个问题,在每一列中,它都会考虑旧列的名称及其与值的索引
index 0 1 2
0 a14468 7.8 b14468 7.2 c14468 7.6
1 a14469 7.8 b14469 7.1 c14469 7.0
2 a14470 7.9 b14470 7.9 c14470 8.1
3 a14471 8.2 b14471 9.5 c14471 9.9
所以我测试了分割函数:
dfnew2['a'] = dfnew2[2].split(' ')
但它没有起作用,当我试图拆分这些列时,会发生以下情况:
AttributeError: 'Series' object has no attribute 'split'
是否可能只有每列的值:
index df15LV df15F df15PC
0 7.8 7.2 7.6
1 7.8 7.1 7.0
2 7.9 7.9 8.1
3 8.2 9.5 9.9
如果列表长度相等,则可以创建一个空的数据帧并填充它:
我认为您需要用^{} 拆分
apply
,并用str[1]
选择:另一种解决方案是使用
^{2}$list comprehension
进行拆分:相关问题 更多 >
编程相关推荐