0

I'm trying to combine three fields to make a date, the year is currently string: code to change string to datetime:

f2[:,'frt_eli_year'] = pd.to_datetime(f2['frt_eli_year'].astype(str), format='%Y',errors='coerce',utc=True)

error message:

TypeError: unhashable type: 'slice'

Then code to join year, month, date:

f2[:,'test'] = pd.to_datetime(f2['frt_eli_year'].dt.year,f2['frt_eli_year'].dt.month,f2['frt_eli_year'].dt.day)

Appreciate the help, thanks!

Quang Hoang
  • 146,074
  • 10
  • 56
  • 74
mccambe
  • 11
  • 4

1 Answers1

0

The mistake is in f2[:,'frt_eli_year']. Check this this answer. Basically it'll work if you change to f2.loc[:,'frt_eli_year'], or or since you want all rows, just f2['frt_eli_year'].

In total:

f2['frt_eli_year'] = pd.to_datetime(f2['frt_eli_year'], 
                                    format='%Y', errors='coerce', utc=True)
Bertil Johannes Ipsen
  • 1,656
  • 1
  • 14
  • 27