TypeError: read_csv() got an unexpected keyword argument ‘date_format’ – Please help me out with this error
While running the script i got this error. Please help me fix this error. I am using Macbook pro, Apple M1 Pro Chip, Mac OS Sonoma Version 14.5. Please find the script below:
from datetime import datetime, timedelta, tzinfo,date,time
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.dates as dates
from matplotlib.dates import DateFormatter
import matplotlib.dates as mdates
import seaborn as sns
#%matplotlib inline
InfileT = "Users\ramanujadasan\Data\Telemetry\RFValidation\Telemetry.csv"
InfileM = "Users\ramanujadasan\Data\Telemetry\RFValidation\Manual.csv"
Tdata = pd.read_csv(InfileT,header = 0,index_col=0,parse_dates=['Date And Time (UTC)'], date_format="%d-%m-%Y %H:%M:%S")
Mdata = pd.read_csv(InfileM,header = 0,index_col=0,parse_dates=['Date And Time (UTC)'], date_format="%d-%m-%Y %H:%M:%S")
#Tdata = Tdata.resample('D').sum()
Tdata = Tdata.resample(rule='24H', closed='left', label='left', offset='8H').sum()
Mdata = Mdata.resample(rule='24H', closed='left', label='left', offset='8H').sum()
print (Tdata.head())
print (Mdata.head())
print (" Manual Data Available from ", Mdata.index[0]," to ",Mdata.index[-1])
print ("n Telemetry Data Available from ", Tdata.index[0]," to ",Tdata.index[-1])
print ("n Default settings for Whole period above. n If selected period requried set value of mode variable to 2 (default value mode =1) and n Modify the start and End date time in script ")
# mode Full time period = 1 , Selected Time period = 2
mode = 1
print ("Selected mode is "+str(mode))
if(mode == 2):
# Algo for selected period
sd = date(2021,5,1)
st = time(2,30,0)
start_date = datetime.combine(sd,st)
ed = date(2021,5,31)
et = time(2,30,0)
end_date = datetime.combine(ed,et)
Tdata = Tdata.loc[start_date:end_date]
Mdata = Mdata.loc[start_date:end_date]
# End Algo for selected period
cheking if Telemetry or Manual has earlier value
Combdata = pd.concat([Tdata, Mdata], axis=0, ignore_index=False)
Combdata['col'] = (len(Tdata)*(0,) + len(Mdata)*(1,))
Combdata['Type'] = ["Manual" if x == 1 else "Telemetry" for x in Combdata['col']]
Combdata['color'] = ["G" if x == 1 else "R" for x in Combdata['col']]
Combdata.reset_index(inplace=True)
Combdata['MonYear'] = Combdata['Date And Time (UTC)'].dt.strftime('%B %Y')
Combdata['Date'] = Combdata['Date And Time (UTC)'].dt.strftime('%d')
sitename = list(Tdata)
Tot_stns = len(sitename)
for i in range (0,Tot_stns):
site = sitename[i]
print (site)
sns.set(font_scale=1)
fig = sns.catplot(data=Combdata.reset_index(),x = 'Date',y = site, hue='Type',kind ='bar', height = 10,aspect = 1,dodge = True,ci= None)
fig.fig.suptitle("Comparision of Telemetry and Manual Rainfall Data at n" +site+ " for " +Combdata['MonYear'][i], fontsize=15, y = 1.1)
#fig.xaxis.set_major_locator(mdates.daylocator(interval=2)) #to get a tick every 15 minutes
#fig.xaxis.set_major_formatter(mdates.DateFormatter('%d:%m')) #optional formatting
fig.set_xticklabels(rotation=90)
#plt.title("Comparision of Telemetry and Manual Rainfall Data at n" +site, fontsize=12)
#plt.figure(figsize(8,4))
#plt.show(fig)
#fig.suptitle('Comparision of Telemetry and Manual Rainfall Data at'+ 'n' +site, fontsize=12)
fig.savefig('Users\ramanujadasan\Data\Telemetry\RFValidation\'+site+".pdf")
Please help me out…
New contributor
Vijaya Durai is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.