I have two DataFrames df1 and df2
df1 = pd.DataFrame(cursor, columns=('Visit_id',
'Lead_Id',
'contact_number',
'Visit_Date',
'City',
'RM',
'call_start_time',
'call_end_time',
'display_name',
'work_type',
'Visit_Scheduled'
))
df2 = pd.DataFrame(cursor, columns=('campaign_name',
'contact_number',
'start_time',
'end_time',
'call_duration',
'agent_id'
))
merged_df = df1.merge(df2, on='contact_number', how='left', indicator=True)
gc = pygsheets.authorize(service_file=r"C:/test/Downloads/keys.json")
sh = gc.open('Test')
sheet1=sh.worksheet_by_title('Dump')
sheet1.clear(start='A',end='Q')
sheet1.set_dataframe(merged_df,start=(1,1))
print('merged_df')
I am getting error as below :
Traceback (most recent call last):
File "C:\Users\ABHISH~1\AppData\Local\Temp/ipykernel_14896/96025778.py", line 1, in <module>
runfile('C:/Users/test/Pictures/Python Codes/AMEYOTEST.py', wdir='C:/Users/test/Pictures/Python Codes')
File "C:\ProgramData\Anaconda3\lib\site-packages\debugpy\_vendored\pydevd\_pydev_bundle\pydev_umd.py", line 167, in runfile
execfile(filename, namespace)
File "C:\ProgramData\Anaconda3\lib\site-packages\debugpy\_vendored\pydevd\_pydev_imps\_pydev_execfile.py", line 25, in execfile
exec(compile(contents + "\n", file, 'exec'), glob, loc)
File "C:/Users/test/Pictures/Python Codes/AMEYOTEST.py", line 192, in <module>
sheet1.set_dataframe(merged_df,start=(1,1))
File "C:\ProgramData\Anaconda3\lib\site-packages\pygsheets\utils.py", line 163, in wrapper
return func(*args, **kwargs)
File "C:\ProgramData\Anaconda3\lib\site-packages\pygsheets\worksheet.py", line 1367, in set_dataframe
df = df.fillna(nan)
File "C:\ProgramData\Anaconda3\lib\site-packages\pandas\util\_decorators.py", line 311, in wrapper
return func(*args, **kwargs)
File "C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\frame.py", line 5176, in fillna
return super().fillna(
File "C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\generic.py", line 6382, in fillna
new_data = self._mgr.fillna(
File "C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\internals\managers.py", line 410, in fillna
return self.apply(
File "C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\internals\managers.py", line 327, in apply
applied = getattr(b, f)(**kwargs)
File "C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\internals\blocks.py", line 1573, in fillna
values = self.values.fillna(value=value, limit=limit)
File "C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\arrays\_mixins.py", line 246, in fillna
self._validate_setitem_value(value)
File "C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\arrays\categorical.py", line 2043, in _validate_setitem_value
raise ValueError(
**ValueError: Cannot setitem on a Categorical with a new category, set the categories first**
What I have tried:
I simply wants to print merged_df values in google sheets