1

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.

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.

Celius Stingher
  • 17,835
  • 6
  • 23
  • 53
Josh Dan
  • 13
  • 2

1 Answers1

0

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]
Celius Stingher
  • 17,835
  • 6
  • 23
  • 53