5

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

1 Answer 1

7

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

Sign up to request clarification or add additional context in comments.

2 Comments

To be clear: the dim argument should be an informative name for the new dimension which distinguishes each original DataFrame from each other, so here it would be something like dim="file_bit". It has nothing to do with the fact you are concatenating them into an xarray Dataset.
I have a similar problem to this one, could you help me out with it? Here is my question: stackoverflow.com/q/58358170/5838180

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.