I am working on a project where I import SQLite database in data frame and then convert string dates to dates using
toCorrect = ["dt_ocurred", "init_action_ship_dt","target_dt", "final_action_ship_dt", "done_dt",
"update_dt", "ext_dt", "PSC_picdt", "PSC_info2ownr_dt", "PSC_info2chrtr_dt", "PSC_info2rtshp_dt",
"PSC_info2oilmaj_dt", "PSC_info2mmstpmgmt_dt", "PSC_sndr_offimport_dt"]#
for someCol in toCorrect:
df_data[someCol] = pd.to_datetime(df_data[someCol],errors='coerce').apply(lambda x: x.date())
after the conversion I am trying to get data for the current year for which i have the following query
curr_year = datetime.datetime.now().year
df_currDRS = df_rawData.query(
f"ship_name == '{shipName}' and (dt_ocurred.str.contains('{curr_year}') or done_dt.str.contains"
f"('{curr_year}') or status.str.contains('OPEN'))", engine='python')
For some reason which i cannot figure out i get this error
AttributeError: Can only use .str accessor with string values!
Traceback:
File "c:\users\sshukla\documents\drs2022\venv\lib\site-packages\streamlit\scriptrunner\script_runner.py", line 443, in _run_script
exec(code, module.__dict__)
File "C:\Users\sshukla\Documents\DRS2022\main.py", line 22, in <module>
make_NewDRS()
File "C:\Users\sshukla\Documents\DRS2022\GetNewDRS.py", line 39, in make_NewDRS
df_currDRS = df_rawData.query(
File "c:\users\sshukla\documents\drs2022\venv\lib\site-packages\pandas\core\frame.py",
I could figure out this much that if I do not convert the string dates to date object then the query runs fine. But I want to know how to construct the query if the dates have been converted from string to date.
Any help would be greatly appreciated.