0

I'm trying to convert an entire column containing a 5 digit date code (EX: 43390, 43599) to a normal date format. This is just to make data analysis easier, it doesn't matter which way it's formatted. In a series, the DATE column looks like this:

1         43390
2         43599
3         43605
4         43329
5         43330
          ...  
264832    43533
264833    43325
264834    43410
264835    43461
264836    43365

I don't understand previous submissions with this question, and when I tried code such as

date_col = df.iloc[:,0]
print((datetime.utcfromtimestamp(0) + timedelta(date_col)).strftime("%Y-%m-%d")) 

I get this error

unsupported type for timedelta days component: Series

Thanks, sorry if this is a basic question.

sprite
  • 1
  • 1
  • No question is basic, every question is interesting. You should check if what you pass to your `timedelta` function is an integer. – Snowfire777 Aug 04 '21 at 21:14
  • These are excel dates `date_col = pd.to_datetime(date_col, unit='d', origin='1899-12-30')` or if updating the DataFrame `df.iloc[:, 0] = pd.to_datetime(df.iloc[:, 0], unit='d', origin='1899-12-30')` – Henry Ecker Aug 04 '21 at 21:21

1 Answers1

0

You are calling the dataframe and assigning it to date_col. If you want to get the value of your first row, for example, use date_col = df.iloc[0]. This will return the value. Timedelta takes an integer value, not Series.

Anurag Saxena
  • 388
  • 2
  • 7