4

In order to join two dataframes df_A and df_B where a date of df_A should lie between a date range of dataframe df_B I am using pandasql. However i noticed that pandasql does not return a proper date (datetime64) as in the original dataframe but a string (object). Is there an easy way to solve this or do i have to apply a string to date conversion everytime I have executed a query?

import pandasql as ps
sql = """select invoice_date from df_A"""
ps.sqldf(sql, locals())

I would expect this output to be the same as just df_A.loc[:,'invoice_date']

Instead as an example this gives me '2018-01-02 00:00:00.000000' (as a string) rather than '2018-01-02' (as date)

David Buck
  • 3,752
  • 35
  • 31
  • 35
Beerbrewer
  • 41
  • 2

1 Answers1

0

you can convert the object datatype to datetime

df_A['invoice_date'] = pd.to_datetime(df_A['invoice_date'])

this will change the dataframe to expected output

anil tiwari
  • 195
  • 13