Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

ValueError: Length of values (4) does not match length of index (179) Pandas

I am using Pandas.

I have a dataset where I scraped linkedin for a company’s employee data.

I am trying to slice a list in one column and make a new column with the slice but get this error.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

This is what I tried.

  1. I filled in every nan with the word "blank"
    2)I split the column into a list on spaces.
employees = employees.fillna("blank")

employees["jobDateRange"] = employees["jobDateRange"].str.split(" ")

The Result:

[Aug, 2013, –, Present]

Then I tried:

employees["job1month"] = employees["jobDateRange"][0]

And I get:

ValueError: Length of values (4) does not match length of index (179)

Can someone help me understand what I am doing wrong and what this error means? (Hopefully in plain English. I can’t understand any of the other StackOverflow answers.

>Solution :

This is a bit tricky, but to access an item in a list within a pandas series, you must also use str. Therefore, you should replace:

employees["job1month"] = employees["jobDateRange"][0]

With:

employees["job1month"] = employees["jobDateRange"].str[0]
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading