Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test update sig rules #35

Merged
merged 5 commits into from
Feb 23, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update update_es_rules.py
replaced datetime with date format, since we don't need time level info; adjusted input prompt to add space and be consistent with expected input
  • Loading branch information
mfebrizio committed Feb 23, 2024
commit ab26c6dd0c7963e861e1b629cf793e2a33366aa2
20 changes: 10 additions & 10 deletions data/es_rules/update_es_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import pandas as pd
import os
import sys
from datetime import datetime
from datetime import datetime, date

#%% Import the current dataset
dir_path=os.path.dirname(os.path.realpath(__file__))
Expand Down Expand Up @@ -33,15 +33,15 @@
#%% FR tracking data
df_fr = pd.read_csv(f'{dir_path}/../fr_tracking/fr_tracking.csv', encoding="ISO-8859-1")

df_fr['publication_date']=df_fr['publication_date'].astype('datetime64[ns]')
df_fr['publication_date'] = pd.to_datetime(df_fr['publication_date'], format="mixed").dt.date
df_fr['econ_significant'] = pd.to_numeric(df_fr['econ_significant'], errors='coerce')
df_fr['3(f)(1) significant']=pd.to_numeric(df_fr['3(f)(1) significant'], errors='coerce')

#%% Get user input pn presidential party
def input_party(year):
party_option = ['democratic','d','republican','r']
while True:
party=input(f'Is presidential year {year} Democratic (D) or Republican (R)?').lower()
party=input(f'Is presidential year {year} Democratic (d) or Republican (r)? >>> ').lower()
if party in party_option:
output='Democratic' if (party in ['democratic','d']) else 'Republican'
return output
Expand All @@ -53,22 +53,22 @@ def input_party(year):
update_data=[]
for year in range(first_year_to_update,last_year_to_update+1):
if year==2023:
count1=df_fr[(df_fr['publication_date']>=datetime(year,2,1)) & \
(df_fr['publication_date']<datetime(year,4,6))]['econ_significant'].sum()
count2=df_fr[(df_fr['publication_date']>=datetime(year,4,6)) & \
(df_fr['publication_date']<=datetime(year+1,1,31))]['3(f)(1) significant'].sum()
count1=df_fr[(df_fr['publication_date'] >= date(year,2,1)) & \
(df_fr['publication_date'] < date(year,4,6))]['econ_significant'].sum()
count2=df_fr[(df_fr['publication_date'] >= date(year,4,6)) & \
(df_fr['publication_date'] <= date(year+1,1,31))]['3(f)(1) significant'].sum()
count=count1+count2
else:
col='econ_significant' if year<2023 else '3(f)(1) significant'
count=df_fr[(df_fr['publication_date']>=datetime(year,2,1)) & \
(df_fr['publication_date']<=datetime(year+1,1,31))][col].sum()
count=df_fr[(df_fr['publication_date']>=date(year,2,1)) & \
(df_fr['publication_date']<=date(year+1,1,31))][col].sum()

party=input_party(year)
update_data.append([year,party,count])
print(f'Presidential year {year} has been updated.')

#%% Append new data
df=pd.concat([df, pd.DataFrame(update_data, columns=df.columns[0:3])], ignore_index=True)
df = pd.concat([df, pd.DataFrame(update_data, columns=df.columns[0:3])], ignore_index=True)

#%% Export
df.to_csv(file_path, index=False)
Expand Down