-1

i have a large python list of size "4" but it is 4 large dataframes. I am trying to convert it to an np array of expected 3 dimension and I cannot figure out why I'm getting this error:

 data2 = np.asarray(data)

The tail end of 'data' looks like this and you can see there are mixed datatypes:

 32133  20210831  2200                 882.2  342259.UNITED STATES.WYEAST.RADIATION.csv
 32134  20210831  2300                 918.9  342259.UNITED STATES.WYEAST.RADIATION.csv
 32135  20210901     0                   NaN  342259.UNITED STATES.WYEAST.RADIATION.csv
 32136  20210901   100                   NaN  342259.UNITED STATES.WYEAST.RADIATION.csv]

I'm getting this error and I'm not sure how to set the datatypes for integers, numeric and text found in my list "data".

ValueError: cannot copy sequence with size 32137 to array axis with dimension 4

Thank you for your help,

user2100039
  • 1,280
  • 2
  • 16
  • 31
  • Downvoting because not reproducible. – zabop Oct 01 '21 at 21:46
  • i'm happy to make this reproducible but my data is huge. I'm not sure how to reproduce a 4-d list to use as an example. – user2100039 Oct 01 '21 at 21:52
  • [This](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples) might help. – zabop Oct 01 '21 at 21:54
  • Thanks, i was able to find the exact answer after lots of looking and I've shown it here below - maybe it will help someone down the road:) – user2100039 Oct 01 '21 at 22:08

1 Answers1

0

Since this was downvoted and not reproducible, I was able to find a reproducible problem and solution that can be found here:

https://blog.finxter.com/how-to-convert-list-of-lists-to-numpy-array/

# Create the list of lists
lst = [[1, 2, 3], [4, 5], [6, 7, 8]]
# Convert it to a NumPy array
a = np.array([np.array(x) for x in lst])
user2100039
  • 1,280
  • 2
  • 16
  • 31