简体   繁体   中英

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

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)

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'))

错误代码

代码无错误

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM