TypeError: parse() takes 1 positional argument but 6 were given

1.9k Views Asked by At

I am trying to run below code but everytime I am getting a typing error.

def parse(x):
    return datetime.strptime(x, '%Y %-m %-d %-H:%-M:%-S')

dataset = read_csv('ID1887011.csv', delimiter=",", parse_dates = [['year', 
'month','day','hours','minutes', 'seconds']], 
               index_col=0, date_parser=parse)
2

There are 2 best solutions below

0
On

Hi I made some changes in the code and now its working.

dataset = pd.read_csv('ID1887011.csv', delimiter=",", index_col='datetime', 
parse_dates = {'datetime': [1,2,3,4,5,6]}, date_parser=lambda x: 
pd.datetime.strptime(x, '%Y %m %d %H %M %S'))
0
On

Code with error

Code without error

First image is error code and second is correct code. You don't need to change the code. In your code i think you import datetime instead you need to from datetime import datetime