I have the list containing big data with time stamps. I would like to achieve the data frame with the time stamps as the first column and the values1, value2,... as next coumns.
My code gives out this small data frame
valList = ['value1','value2','value3','value4','value5','value6','value7','value8','value9','value10','value11','value12','value13','value14','value15']
pd.DataFrame([df],columns = valList)
Thats how the list looks like.
CodePudding user response:
Here you'll find the Answers. I just created a new df, please compare it to your df.
import pandas as pd
x = [1,2,3,5]
y = [1,2,3,5]
z = [1,2,3,5]
df = pd.DataFrame(list(zip(x, y, z)), columns=["x", "y", "z"])
df
CodePudding user response:
It looks like you are creating a DataFrame object from a list of pandas Series.
It also looks like those Series have already an appropriate column name.
The only thing you need to do is to concatenate those Series column-wise, making sure that they're all of the same length.
According to pandas.concat documentation, you can do:
df = pd.concat([series_objs], axis=1)
where [series_objs]
is your list of pandas.Series
objects.
CodePudding user response:
First, you can split your data into timestamps and data values
#I am using a small list to demonstrate:
l=['2018-10-01 00:00:00 00:00 28385.21','2018-10-01 00:00:00 00:00 12280.00']
create another list from an empty list k
k=[]
for x in l:
k.append(x.split(' ')) # there are 2 blank spaces in split to separate date with values
Now, k
will look like this:
[['2018-10-01 00:00:00 00:00', '28358'],
['2018-10-01 00:00:00 00:00', '21358']]
Once, you get k will all the values, covert it into a dataframe:
pd.DataFrame(k) # you can change the names of columns in this function according to your need
0 2018-10-01 00:00:00 00:00 28358
1 2018-10-01 00:00:00 00:00 21358