0

I need a column of strings, 'yyyymmdd', converted to date so I can do an operation (subtract one day) and then return the format to string. The combined method works in the line below, but seems to take considerably longer than two separate functions would. Ideas?

df['yyyymmdd-0'] = (pd.to_datetime(df.yyyymmdd, format='%Y%m%d')+ pd.DateOffset(days=0)).dt.strftime('%Y%m%d')
  • for days you can try `df.yyyymmdd.str[:-1]+(df.yyyymmdd.str[-1].astype(int)-1).astype(str)` – anky Feb 10 '21 at 17:03
  • The string operations (.strftime being one of them) tend to be on the slower side, really no escaping that. – ALollz Feb 10 '21 at 17:06

0 Answers0