I have got the following error:
TypeError: parse() takes 1 positional argument but 2 were given
I was trying to do a basic data preparation where I wanted to parse the date-time information as a Panda DataFrame index (combine the 'date' and 'time' columns together in a single column). This is a snippet of the code:
from pandas import read_csv
from datetime import datetime
def parse(x):
return datetime.strptime(x,'%d-%b-%y %H:%M:%S' )
dataset = read_csv("dataset.csv", header=0, parse_dates = [['date', 'time']],
index_col=0, date_parser= parse)
This is how the original date and time look like:
date time
25-Apr-17 19:19:40
25-Apr-17 19:19:40
25-Apr-17 19:19:45
25-Apr-17 19:19:45
I came across an alternative way to use:
dataset = read_csv("dataset.csv", header=0, parse_dates = {'datetime':[1,2]},
index_col=0, date_parser=lambda x: datetime.strptime(x,'%d-%b-%y %H:%M:%S' )
But still the same issue. TypeError: <lambda>() takes 1 positional argument but 2 were given
I was wondering if you guys could help me with this issue?