I have a pandas dataframe df whose elements are each a whole numpy array. For example the 6th row of column 'x_grid':
>>> e = df.loc[6,'x_grid']
>>> print(e)
[-11.52616579 -11.48006112 -11.43395646 -11.3878518 -11.34174713
-11.29564247 -11.24953781 -11.20343315 -11.15732848 -11.11122382
-11.06511916 -11.01901449 ...
But I cannot use this as a numpy array as it is just given as a string:
>>> print(type(e))
<class 'str'>
How can I store a numpy array to a dataframe so it does not get converted to a string? Or convert this string back to a numpy array in a nice way?
[], Are there also...? The original dataframe had these array items, and the only way to save such a df to a 2d csv format is turn the complex items into strings. pandas usedstr(item). Where possible avoid saving such dataframes as csv.literal_evalmight have problems with your string because it is missing the commas that normally mark a list.