Skip to content
Advertisement

Creating pandas series from array and list

I’m trying to map array data to a list of column names

JavaScript

but keep getting this error message

JavaScript

This is a sample of the data in a

JavaScript

and the list of rows in cols:

JavaScript

The endgoal is to create a series showing the coefficients of each feature (represented by the cols list)

Advertisement

Answer

You array is having an array inside it. You have 32 column values, but your row array has a length of 1. As a result, your lengths of corresponding rows and columns don’t match. What you need instead is the inner array which has a length of 32. You can access it using the index 0.

Therefore, try the following:

JavaScript

In case your array has further nested arrays inside, and you don’t want to use multiple indices such as a[0][0] etc., you can flatten your array using either of the two options

JavaScript

or

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement