0

I have a dataset with a column named ['STime'] that I want to use to create many columns containing each time element (Year, Month, day, etc). The column values have this format 2016-04-16 10:12:41. I tried creating a year column separately using:

 data['SYear'] = data['SDate'].year

It gave me an error: AttributeError: 'Series' object has no attribute 'year'

How can I solve this?

principe
  • 173
  • 1
  • 1
  • 11

1 Answers1

1

data['SDate'] is a series, a series has no attribute year. However, you can map a series through a function and save the result in a new column, like:

data['SYear'] = data['SDate'].map(lambda d: d.year)

This will map each value of the column SDate through the lambda function and generate a new Pandas series, which will be saved in the new column.

Lucas Abbade
  • 757
  • 9
  • 19