0

As a start, I am extremely new at Python.

I am receiving an Excel file where the date field is incomplete. The value displays as "190808" (YYMMDD) instead of "2019-08-08".

Part of my automation attempt is to move the file to a different location, where the file is renamed. I want to use the date field to change the file name to the file description and date (e.g. "Sales figures 201908").

The code I have only works if the date format is

str(df['Bank date'][0].strftime("%Y%m"))

I have tried dateparser with the following:

dateparser.parse(df['Bank date'][0].strftime("%Y.%m"))

The error I am receiving is 'numpy.int64' object has no attribute 'strftime'

Any help will do.

Thanks.

ben
  • 81
  • 8

2 Answers2

0

I modified it slightly and built my own date-string using slicing.

vOldDate = str(df['Bank date'][0])
vNewDate = '20' + vOldDate[:2] + '.' + vOldDate[2:4]
ben
  • 81
  • 8
0

Numpy is interpreting the date as an integer. To use dateparser, you need to convert that value into a string first, then parse that string, and then format the result:

dateparser.parse(str(df['Bank date'][0])).strftime("%Y.%m")

Since the input format is expected, you should specify it to ensure you get the right date:

>>> dateparser.parse(str(190808), date_formats=['%y%m%d']).strftime("%Y.%m")
'2019.08'
Gallaecio
  • 3,620
  • 2
  • 25
  • 64