0

I have a dataset with one column that I want to change to date-time format. If I use this:

df = pd.to_datetime(df['product_first_sold_date'],unit='d',origin='1900-01-01')

df will only have this one particular column while all others are removed. Instead, I want to keep the remaining columns unchanged and just apply the to_datetime function to one column.

I tried using loc with multiple ways, including this:

df.loc[df['product_first_sold_date']] = pd.to_datetime(df['product_first_sold_date'],unit='d',origin='1900-01-01')

but it throws a key error.

How else can I achieve this?

x89
  • 2,798
  • 5
  • 46
  • 110

1 Answers1

3
df['product_first_sold_date'] = pd.to_datetime(df['product_first_sold_date'],unit='d',origin='1900-01-01')

should work i think

Joran Beasley
  • 110,522
  • 12
  • 160
  • 179