1

I would like to add another Column with only the Filing Year. Can anyone help me how to do it?

The current DataType of the Filing Data Column is Object. Is that okay or do I need to convert it?

        Issuer                      Filing Data
0       Lear Seating Corp           1994-03-08
1       Mississippi Chemical Corp   1994-07-14
2       Lucent Technologies Inc     1996-02-05
3       Ryerson Tull Inc            1996-05-07
4       Providence Journal Co       1996-04-22 

BR and thanks in advance!

Peter Wood
  • 23,859
  • 5
  • 60
  • 99

2 Answers2

0

Try This:

df['year'] = pd.DatetimeIndex(df['Filing Data']).year

And here's the link:

https://www.interviewqs.com/ddi_code_snippets/extract_month_year_pandas

Note : He uses this on a columns of type panda series

omar_9
  • 19
  • 1
  • 6
0

Try:

df['Filing_Year'] = [val.split('-')[0] for val in df['Filing_Data']]

df:

                      Issuer Filing_Data Filing_Year
0          Lear Seating Corp  1994-03-08        1994
1  Mississippi Chemical Corp  1994-07-14        1994
Ahmet
  • 7,527
  • 3
  • 23
  • 47