I am working with a bucketload of data that has the form:
import pandas as pd
import numpy as np
lat = np.array([80.589, 80.592, 80.595])
lon = np.array([50.268, 50.264, 50.260])
wav = np.array([[486, 605, 666, 821, 777, 719],
[ 65, 60, 68, 67, 72, 64],
[866, 946, 882, 855, 999, 1195]])
print("lat shape:",lat.shape)
print("lon shape:",lon.shape)
print("wav shape:",wav.shape)
# lat shape: (3,)
# lon shape: (3,)
# wav shape: (3, 6)
df = pd.DataFrame({
'Lon': lon,
'Lat': lat,
'Wav': wav})
which gives the error "ValueError: Per-column arrays must each be 1-dimensional"
I can work around this by converting the guts of wav to a string and back again when I need it, but that is Ugly Gross, and I would like to find the proper way to handle mix dimension arrays in a pandas dataframe.
Desired result:
print(df.head(1))
Lon Lat Wav
0 50.268 80.589 [486, 605, 666, 821, 777, 719]
>Solution :
How about using a list of lists ?
df = pd.DataFrame({
'Lon': lon,
'Lat': lat,
'Wav': [list(wav_row) for wav_row in wav]
})
