I have three lists filled with data and I would like to concatenate them to create a dataframe
type of data_activationsLV : list
type of data_activationsF : list
type of data_activationsPC : list
The structure of the data for the three lists :
data_activationsLV data_activationsF data_activationsPC
index a index b index c
14468 7.8 14468 7.2 14468 7.6
14469 7.8 14469 7.1 14469 7.0
14470 7.9 14470 7.9 14470 8.1
14471 8.2 14471 9.5 14471 9.9
..
I transform them into series and concate them :
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)
by cons here I have a problem, in each column, it considers the name of the old column and its index with the value
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
So I tested the split function :
dfnew2['a'] = dfnew2[2].split(' ')
But it did not work,When I try to split those columns, this is what happens:
AttributeError: 'Series' object has no attribute 'split'
Is it possible to have only the values for each columns:
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
if you have lists of equal length, you could just create an empty dataframe and fill it:
I think you need for splitting
apply
withstr.split
and selecting withstr[1]
:Another solution is use
list comprehension
for splitting: