[Solved] how to save sql query result to csv in pandas


You can try following code:

import pandas as pd

df1 = pd.read_csv("Insert file path")
df2 = pd.read_csv("Insert file path")

df1['Date'] = pd.to_datetime(df1['Date'] ,errors="coerce",format="%Y-%m-%d")
df2['Date'] = pd.to_datetime(df2['Date'] ,errors="coerce",format="%Y-%m-%d")

df = df1.merge(df2,how='inner', on ='Date')
df.to_csv('data.csv',index=False)

This should solve your problem.

4

solved how to save sql query result to csv in pandas