Jan-05-2023, 10:35 PM
The followings are my code and prints. Why the df_sample is empty? The ydate variable is '2022-12-31' and the original df As_of_date have '2022-12-31'. Thanks.
Code:
sql = """
select *
from working.Temp
where As_of_date = '2022-12-31'"""
df = pd.read_sql(sql,cnxn)
date1 = datetime.datetime.now() - timedelta(days = 5)
ydate = (date1.strftime("%Y-%m-%d"))
df_sample = df.loc[(df['As_of_date'] == ydate)]
print(ydate)
print('df_sample')
print(df_sample)
print('df')
print(df)
Output:
2022-12-31
df_sample
Empty DataFrame
Columns: [As_of_date, Term, Current_Bal, Amount1, Amount2]
Index: []
df
As_of_date Term Current_Bal Amount1 Amount2
0 2022-12-31 144.0 18665.43 186467.6457 12953808.42
1 2022-12-31 144.0 14476.56 144620.8344 11364099.60
2 2022-12-31 84.0 8473.60 59230.4640 6134886.40
3 2022-12-31 180.0 11744.23 82092.1677 7833401.41
4 2022-12-31 144.0 10481.00 157110.1900 6802169.00
Code:
sql = """
select *
from working.Temp
where As_of_date = '2022-12-31'"""
df = pd.read_sql(sql,cnxn)
date1 = datetime.datetime.now() - timedelta(days = 5)
ydate = (date1.strftime("%Y-%m-%d"))
df_sample = df.loc[(df['As_of_date'] == ydate)]
print(ydate)
print('df_sample')
print(df_sample)
print('df')
print(df)
Output:
2022-12-31
df_sample
Empty DataFrame
Columns: [As_of_date, Term, Current_Bal, Amount1, Amount2]
Index: []
df
As_of_date Term Current_Bal Amount1 Amount2
0 2022-12-31 144.0 18665.43 186467.6457 12953808.42
1 2022-12-31 144.0 14476.56 144620.8344 11364099.60
2 2022-12-31 84.0 8473.60 59230.4640 6134886.40
3 2022-12-31 180.0 11744.23 82092.1677 7833401.41
4 2022-12-31 144.0 10481.00 157110.1900 6802169.00