I have a python program in which i read a csv file onto a Pandas dataframe. Then I want to plot my sensor value with datetime in a clean format. My code gives error ValueError: time data ' 2017/02/17' does not match format '%Y/%m/%d %H:%M:%S.%f. My Code and some rows from dataframe is below:
Code:
import pandas as pd
from datetime import datetime
import csv
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
headers = ['Sensor Value','Date','Time']
df = pd.read_csv('C:/Users\Lala Rushan\Downloads\DataLog.CSV', parse_dates= {'Datetime': [1,2]},names=headers)
print (df)
df['Datetime'] = df['Datetime'].map(lambda x: datetime.strptime(str(x), "%y/%m/%d , %H:%M:%S.%f"))
#datetime.strptime(df['Datetime'],"%Y/%m/%d %H:%M:%S.%f")
x = df['Datetime']
y = df['Sensor Value']
# plot
plt.plot(x,y)
# beautify the x-labels
plt.gcf().autofmt_xdate()
plt.show()
DataFrame:
Datetime Sensor Value
0 2017/02/17 19:06:17.188 2
1 2017/02/17 19:06:22.360 72
2 2017/02/17 19:06:27.348 72
3 2017/02/17 19:06:32.482 72
4 2017/02/17 19:06:37.515 74
5 2017/02/17 19:06:42.580 70
6 2017/02/17 19:06:47.660 72
How can i solve this error? I'm newvie to python so pardon any basic mistakes.

"2017/02/17"but your posted dataframe looks like it should be"2017/02/17 19:06:17.188"(also note no comma) or similar.pandas's datetime parser:df['Datetime'] = pd.to_datetime(df['Datetime'])insteading of trying to usemapto parse each row value. This should parse the entire field intodatetimeif the format is consistent all throughout.