Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xarray.DataSet from a list of Pandas.DataFrames

I have multiple files with bits to analyse. First i read them into a list of BitString.Bits. Then i split each file bits into the specific parts i want to see and save them into a list of Pandas.DataFrames. One DF for each file.

Now for further plotting and analysis purposes i want to store all data in one Xarray.Dataset, where i have the DataFrames stacked along the third axis with the name "dataset".

I have tried to concat each DataFrame together to an DataSet:

xr.concat(data_df[:], dim="dataset")

but i got an error saying that i cant concatenate other than DataArray or DataSets. Can i convert the DataFrames on the fly to DataArrays?

Thanks for your help!

Greetings from Germany

Jan

like image 687
Jan Jansen Avatar asked May 26 '17 10:05

Jan Jansen


1 Answers

you can use DataFrame.to_xarray() method:

xr.concat([df.to_xarray() for df in data_df], dim="dataset")

where data_df is a list of DataFrames

like image 107
MaxU - stop WAR against UA Avatar answered Oct 31 '22 15:10

MaxU - stop WAR against UA