import requests
import polars as pl
import polars.selectors as cs
from plotnine import *
from great_tables import *
In [1]:
In [2]:
= []
res = 'https://www.federalregister.gov/api/v1/documents.json?fields[]=document_number&fields[]=excerpts&fields[]=page_length&fields[]=president&fields[]=publication_date&fields[]=raw_text_url&fields[]=signing_date&fields[]=title&fields[]=toc_subject&fields[]=topics&per_page=20&conditions[publication_date][gte]=2005-01-20&conditions[presidential_document_type][]=executive_order&conditions[president][]=george-w-bush&conditions[president][]=barack-obama&conditions[president][]=donald-trump&conditions[president][]=joe-biden&conditions[president][]=donald-trump'
url
while url != '':
# retrieve results
= requests.get(url)
response
response.raise_for_status()= response.json()
res_temp += [res_temp]
res
# get next url
= res_temp.get('next_page_url','') url
In [3]:
= (
df_res
pl.DataFrame(res)'results')
.select('results')
.explode('results')
.unnest('president')
.unnest(
) df_res.glimpse()
Rows: 969
Columns: 11
$ document_number <str> '2025-14212', '2025-14217', '2025-14218', '2025-13925', '2025-12961', '2025-12962', '2025-12774', '2025-12775', '2025-12505', '2025-12506'
$ excerpts <null> None, None, None, None, None, None, None, None, None, None
$ page_length <i64> 4, 3, 3, 3, 2, 2, 3, 2, 1, 5
$ identifier <str> 'donald-trump', 'donald-trump', 'donald-trump', 'donald-trump', 'donald-trump', 'donald-trump', 'donald-trump', 'donald-trump', 'donald-trump', 'donald-trump'
$ name <str> 'Donald Trump', 'Donald Trump', 'Donald Trump', 'Donald Trump', 'Donald Trump', 'Donald Trump', 'Donald Trump', 'Donald Trump', 'Donald Trump', 'Donald Trump'
$ publication_date <str> '2025-07-28', '2025-07-28', '2025-07-28', '2025-07-23', '2025-07-10', '2025-07-10', '2025-07-09', '2025-07-09', '2025-07-03', '2025-07-03'
$ raw_text_url <str> 'https://www.federalregister.gov/documents/full_text/text/2025/07/28/2025-14212.txt', 'https://www.federalregister.gov/documents/full_text/text/2025/07/28/2025-14217.txt', 'https://www.federalregister.gov/documents/full_text/text/2025/07/28/2025-14218.txt', 'https://www.federalregister.gov/documents/full_text/text/2025/07/23/2025-13925.txt', 'https://www.federalregister.gov/documents/full_text/text/2025/07/10/2025-12961.txt', 'https://www.federalregister.gov/documents/full_text/text/2025/07/10/2025-12962.txt', 'https://www.federalregister.gov/documents/full_text/text/2025/07/09/2025-12774.txt', 'https://www.federalregister.gov/documents/full_text/text/2025/07/09/2025-12775.txt', 'https://www.federalregister.gov/documents/full_text/text/2025/07/03/2025-12505.txt', 'https://www.federalregister.gov/documents/full_text/text/2025/07/03/2025-12506.txt'
$ signing_date <str> '2025-07-23', '2025-07-23', '2025-07-23', '2025-07-17', '2025-07-07', '2025-07-07', '2025-07-03', '2025-07-03', '2025-06-30', '2025-06-30'
$ title <str> 'Accelerating Federal Permitting of Data Center Infrastructure', 'Preventing Woke AI in the Federal Government', 'Promoting the Export of the American AI Technology Stack', 'Creating Schedule G in the Excepted Service', 'Ending Market Distorting Subsidies for Unreliable, Foreign-Controlled Energy Sources', 'Extending the Modification of the Reciprocal Tariff Rates', "Establishing the President's Make America Beautiful Again Commission", 'Making America Beautiful Again by Improving Our National Parks', 'Establishing a White House Office for Special Peace Missions', 'Providing for the Revocation of Syria Sanctions'
$ toc_subject <str> None, 'Government Agencies and Employees', None, 'Government Agencies and Employees', None, None, None, None, None, None
$ topics <list[null]> [], [], [], [], [], [], [], [], [], []
Rows: 969
Columns: 11
$ document_number <str> '2025-14212', '2025-14217', '2025-14218', '2025-13925', '2025-12961', '2025-12962', '2025-12774', '2025-12775', '2025-12505', '2025-12506'
$ excerpts <null> None, None, None, None, None, None, None, None, None, None
$ page_length <i64> 4, 3, 3, 3, 2, 2, 3, 2, 1, 5
$ identifier <str> 'donald-trump', 'donald-trump', 'donald-trump', 'donald-trump', 'donald-trump', 'donald-trump', 'donald-trump', 'donald-trump', 'donald-trump', 'donald-trump'
$ name <str> 'Donald Trump', 'Donald Trump', 'Donald Trump', 'Donald Trump', 'Donald Trump', 'Donald Trump', 'Donald Trump', 'Donald Trump', 'Donald Trump', 'Donald Trump'
$ publication_date <str> '2025-07-28', '2025-07-28', '2025-07-28', '2025-07-23', '2025-07-10', '2025-07-10', '2025-07-09', '2025-07-09', '2025-07-03', '2025-07-03'
$ raw_text_url <str> 'https://www.federalregister.gov/documents/full_text/text/2025/07/28/2025-14212.txt', 'https://www.federalregister.gov/documents/full_text/text/2025/07/28/2025-14217.txt', 'https://www.federalregister.gov/documents/full_text/text/2025/07/28/2025-14218.txt', 'https://www.federalregister.gov/documents/full_text/text/2025/07/23/2025-13925.txt', 'https://www.federalregister.gov/documents/full_text/text/2025/07/10/2025-12961.txt', 'https://www.federalregister.gov/documents/full_text/text/2025/07/10/2025-12962.txt', 'https://www.federalregister.gov/documents/full_text/text/2025/07/09/2025-12774.txt', 'https://www.federalregister.gov/documents/full_text/text/2025/07/09/2025-12775.txt', 'https://www.federalregister.gov/documents/full_text/text/2025/07/03/2025-12505.txt', 'https://www.federalregister.gov/documents/full_text/text/2025/07/03/2025-12506.txt'
$ signing_date <str> '2025-07-23', '2025-07-23', '2025-07-23', '2025-07-17', '2025-07-07', '2025-07-07', '2025-07-03', '2025-07-03', '2025-06-30', '2025-06-30'
$ title <str> 'Accelerating Federal Permitting of Data Center Infrastructure', 'Preventing Woke AI in the Federal Government', 'Promoting the Export of the American AI Technology Stack', 'Creating Schedule G in the Excepted Service', 'Ending Market Distorting Subsidies for Unreliable, Foreign-Controlled Energy Sources', 'Extending the Modification of the Reciprocal Tariff Rates', "Establishing the President's Make America Beautiful Again Commission", 'Making America Beautiful Again by Improving Our National Parks', 'Establishing a White House Office for Special Peace Missions', 'Providing for the Revocation of Syria Sanctions'
$ toc_subject <str> None, 'Government Agencies and Employees', None, 'Government Agencies and Employees', None, None, None, None, None, None
$ topics <list[null]> [], [], [], [], [], [], [], [], [], []
In [4]:
# lookup table
= [1,2,1,2,1,1,2]
term = [2001, 2005, 2009, 2013, 2017, 2021, 2025]
start_year = [f'{year}-01-20' for year in start_year]
start_date = start_date[1:] + ['2029-01-20']
end_date = ['Bush']*2 + ['Obama']*2 + ['Trump'] + ['Biden'] + ['Trump']
president_lname = pl.DataFrame([term, start_year, start_date, end_date, president_lname],
df_lkup = ['term','start_year','start_date', 'end_date', 'president_lname'],
schema = 'col')
orient df_lkup
shape: (7, 5)
term | start_year | start_date | end_date | president_lname |
---|---|---|---|---|
i64 | i64 | str | str | str |
1 | 2001 | "2001-01-20" | "2005-01-20" | "Bush" |
2 | 2005 | "2005-01-20" | "2009-01-20" | "Bush" |
1 | 2009 | "2009-01-20" | "2013-01-20" | "Obama" |
2 | 2013 | "2013-01-20" | "2017-01-20" | "Obama" |
1 | 2017 | "2017-01-20" | "2021-01-20" | "Trump" |
1 | 2021 | "2021-01-20" | "2025-01-20" | "Biden" |
2 | 2025 | "2025-01-20" | "2029-01-20" | "Trump" |
In [5]:
= (
df_clean
df_res
.with_columns(= pl.col('identifier')
president_lname str.extract('[A-Za-z ]+-([A-Za-z]+$)', group_index = 1)
.str.to_titlecase(),
.
)# there's a bug in polars join_asof() at the time of writing...
= 'president_lname')
.join(df_lkup, on filter( pl.col('signing_date') >= pl.col('start_date'))
.filter( pl.col('signing_date') < pl.col('end_date'))
.= pl.concat_str( pl.col('president_lname'), pl.lit(' - '), pl.col('term')) )
.with_columns( pres_term
) df_clean.glimpse()
Rows: 952
Columns: 17
$ document_number <str> '2025-14212', '2025-14217', '2025-14218', '2025-13925', '2025-12961', '2025-12962', '2025-12774', '2025-12775', '2025-12505', '2025-12506'
$ excerpts <null> None, None, None, None, None, None, None, None, None, None
$ page_length <i64> 4, 3, 3, 3, 2, 2, 3, 2, 1, 5
$ identifier <str> 'donald-trump', 'donald-trump', 'donald-trump', 'donald-trump', 'donald-trump', 'donald-trump', 'donald-trump', 'donald-trump', 'donald-trump', 'donald-trump'
$ name <str> 'Donald Trump', 'Donald Trump', 'Donald Trump', 'Donald Trump', 'Donald Trump', 'Donald Trump', 'Donald Trump', 'Donald Trump', 'Donald Trump', 'Donald Trump'
$ publication_date <str> '2025-07-28', '2025-07-28', '2025-07-28', '2025-07-23', '2025-07-10', '2025-07-10', '2025-07-09', '2025-07-09', '2025-07-03', '2025-07-03'
$ raw_text_url <str> 'https://www.federalregister.gov/documents/full_text/text/2025/07/28/2025-14212.txt', 'https://www.federalregister.gov/documents/full_text/text/2025/07/28/2025-14217.txt', 'https://www.federalregister.gov/documents/full_text/text/2025/07/28/2025-14218.txt', 'https://www.federalregister.gov/documents/full_text/text/2025/07/23/2025-13925.txt', 'https://www.federalregister.gov/documents/full_text/text/2025/07/10/2025-12961.txt', 'https://www.federalregister.gov/documents/full_text/text/2025/07/10/2025-12962.txt', 'https://www.federalregister.gov/documents/full_text/text/2025/07/09/2025-12774.txt', 'https://www.federalregister.gov/documents/full_text/text/2025/07/09/2025-12775.txt', 'https://www.federalregister.gov/documents/full_text/text/2025/07/03/2025-12505.txt', 'https://www.federalregister.gov/documents/full_text/text/2025/07/03/2025-12506.txt'
$ signing_date <str> '2025-07-23', '2025-07-23', '2025-07-23', '2025-07-17', '2025-07-07', '2025-07-07', '2025-07-03', '2025-07-03', '2025-06-30', '2025-06-30'
$ title <str> 'Accelerating Federal Permitting of Data Center Infrastructure', 'Preventing Woke AI in the Federal Government', 'Promoting the Export of the American AI Technology Stack', 'Creating Schedule G in the Excepted Service', 'Ending Market Distorting Subsidies for Unreliable, Foreign-Controlled Energy Sources', 'Extending the Modification of the Reciprocal Tariff Rates', "Establishing the President's Make America Beautiful Again Commission", 'Making America Beautiful Again by Improving Our National Parks', 'Establishing a White House Office for Special Peace Missions', 'Providing for the Revocation of Syria Sanctions'
$ toc_subject <str> None, 'Government Agencies and Employees', None, 'Government Agencies and Employees', None, None, None, None, None, None
$ topics <list[null]> [], [], [], [], [], [], [], [], [], []
$ president_lname <str> 'Trump', 'Trump', 'Trump', 'Trump', 'Trump', 'Trump', 'Trump', 'Trump', 'Trump', 'Trump'
$ term <i64> 2, 2, 2, 2, 2, 2, 2, 2, 2, 2
$ start_year <i64> 2025, 2025, 2025, 2025, 2025, 2025, 2025, 2025, 2025, 2025
$ start_date <str> '2025-01-20', '2025-01-20', '2025-01-20', '2025-01-20', '2025-01-20', '2025-01-20', '2025-01-20', '2025-01-20', '2025-01-20', '2025-01-20'
$ end_date <str> '2029-01-20', '2029-01-20', '2029-01-20', '2029-01-20', '2029-01-20', '2029-01-20', '2029-01-20', '2029-01-20', '2029-01-20', '2029-01-20'
$ pres_term <str> 'Trump - 2', 'Trump - 2', 'Trump - 2', 'Trump - 2', 'Trump - 2', 'Trump - 2', 'Trump - 2', 'Trump - 2', 'Trump - 2', 'Trump - 2'
Rows: 952
Columns: 17
$ document_number <str> '2025-14212', '2025-14217', '2025-14218', '2025-13925', '2025-12961', '2025-12962', '2025-12774', '2025-12775', '2025-12505', '2025-12506'
$ excerpts <null> None, None, None, None, None, None, None, None, None, None
$ page_length <i64> 4, 3, 3, 3, 2, 2, 3, 2, 1, 5
$ identifier <str> 'donald-trump', 'donald-trump', 'donald-trump', 'donald-trump', 'donald-trump', 'donald-trump', 'donald-trump', 'donald-trump', 'donald-trump', 'donald-trump'
$ name <str> 'Donald Trump', 'Donald Trump', 'Donald Trump', 'Donald Trump', 'Donald Trump', 'Donald Trump', 'Donald Trump', 'Donald Trump', 'Donald Trump', 'Donald Trump'
$ publication_date <str> '2025-07-28', '2025-07-28', '2025-07-28', '2025-07-23', '2025-07-10', '2025-07-10', '2025-07-09', '2025-07-09', '2025-07-03', '2025-07-03'
$ raw_text_url <str> 'https://www.federalregister.gov/documents/full_text/text/2025/07/28/2025-14212.txt', 'https://www.federalregister.gov/documents/full_text/text/2025/07/28/2025-14217.txt', 'https://www.federalregister.gov/documents/full_text/text/2025/07/28/2025-14218.txt', 'https://www.federalregister.gov/documents/full_text/text/2025/07/23/2025-13925.txt', 'https://www.federalregister.gov/documents/full_text/text/2025/07/10/2025-12961.txt', 'https://www.federalregister.gov/documents/full_text/text/2025/07/10/2025-12962.txt', 'https://www.federalregister.gov/documents/full_text/text/2025/07/09/2025-12774.txt', 'https://www.federalregister.gov/documents/full_text/text/2025/07/09/2025-12775.txt', 'https://www.federalregister.gov/documents/full_text/text/2025/07/03/2025-12505.txt', 'https://www.federalregister.gov/documents/full_text/text/2025/07/03/2025-12506.txt'
$ signing_date <str> '2025-07-23', '2025-07-23', '2025-07-23', '2025-07-17', '2025-07-07', '2025-07-07', '2025-07-03', '2025-07-03', '2025-06-30', '2025-06-30'
$ title <str> 'Accelerating Federal Permitting of Data Center Infrastructure', 'Preventing Woke AI in the Federal Government', 'Promoting the Export of the American AI Technology Stack', 'Creating Schedule G in the Excepted Service', 'Ending Market Distorting Subsidies for Unreliable, Foreign-Controlled Energy Sources', 'Extending the Modification of the Reciprocal Tariff Rates', "Establishing the President's Make America Beautiful Again Commission", 'Making America Beautiful Again by Improving Our National Parks', 'Establishing a White House Office for Special Peace Missions', 'Providing for the Revocation of Syria Sanctions'
$ toc_subject <str> None, 'Government Agencies and Employees', None, 'Government Agencies and Employees', None, None, None, None, None, None
$ topics <list[null]> [], [], [], [], [], [], [], [], [], []
$ president_lname <str> 'Trump', 'Trump', 'Trump', 'Trump', 'Trump', 'Trump', 'Trump', 'Trump', 'Trump', 'Trump'
$ term <i64> 2, 2, 2, 2, 2, 2, 2, 2, 2, 2
$ start_year <i64> 2025, 2025, 2025, 2025, 2025, 2025, 2025, 2025, 2025, 2025
$ start_date <str> '2025-01-20', '2025-01-20', '2025-01-20', '2025-01-20', '2025-01-20', '2025-01-20', '2025-01-20', '2025-01-20', '2025-01-20', '2025-01-20'
$ end_date <str> '2029-01-20', '2029-01-20', '2029-01-20', '2029-01-20', '2029-01-20', '2029-01-20', '2029-01-20', '2029-01-20', '2029-01-20', '2029-01-20'
$ pres_term <str> 'Trump - 2', 'Trump - 2', 'Trump - 2', 'Trump - 2', 'Trump - 2', 'Trump - 2', 'Trump - 2', 'Trump - 2', 'Trump - 2', 'Trump - 2'
In [6]:
= (
df_agg
df_clean'pres_term')
.group_by(
.agg(= pl.col('document_number').count(),
n_eo_issued = pl.col('publication_date').min()
start_date
)
)
'start_date') df_agg.sort(
shape: (6, 3)
pres_term | n_eo_issued | start_date |
---|---|---|
str | u32 | str |
"Bush - 2" | 118 | "2005-01-31" |
"Obama - 1" | 148 | "2009-01-26" |
"Obama - 2" | 130 | "2013-02-19" |
"Trump - 1" | 220 | "2017-01-24" |
"Biden - 1" | 162 | "2021-01-25" |
"Trump - 2" | 174 | "2025-01-28" |
In [7]:
= (
df_cumul
df_clean'date').cast(pl.Date) )
.with_columns( cs.ends_with(
.with_columns(= ( pl.col('signing_date') - pl.col('start_date') ).dt.total_days(),
day_since_start = pl.concat_str( pl.lit('('), pl.col('start_date').dt.year(), pl.lit(')'),
term_label '\n'),
pl.lit('president_lname') )
pl.col(
)'pres_term', 'term_label', 'day_since_start', 'signing_date')
.group_by(len()
.= pl.col('len').cum_sum().over('pres_term', order_by = 'day_since_start') )
.with_columns( n_cumul
)'pres_term', 'day_since_start').glimpse() df_cumul.sort(
Rows: 711
Columns: 6
$ pres_term <str> 'Biden - 1', 'Biden - 1', 'Biden - 1', 'Biden - 1', 'Biden - 1', 'Biden - 1', 'Biden - 1', 'Biden - 1', 'Biden - 1', 'Biden - 1'
$ term_label <str> '(2021)\nBiden', '(2021)\nBiden', '(2021)\nBiden', '(2021)\nBiden', '(2021)\nBiden', '(2021)\nBiden', '(2021)\nBiden', '(2021)\nBiden', '(2021)\nBiden', '(2021)\nBiden'
$ day_since_start <i64> 0, 1, 2, 5, 6, 7, 8, 13, 15, 21
$ signing_date <date> 2021-01-20, 2021-01-21, 2021-01-22, 2021-01-25, 2021-01-26, 2021-01-27, 2021-01-28, 2021-02-02, 2021-02-04, 2021-02-10
$ len <u32> 9, 8, 2, 2, 1, 2, 1, 3, 1, 1
$ n_cumul <u32> 9, 17, 19, 21, 22, 24, 25, 28, 29, 30
Rows: 711
Columns: 6
$ pres_term <str> 'Biden - 1', 'Biden - 1', 'Biden - 1', 'Biden - 1', 'Biden - 1', 'Biden - 1', 'Biden - 1', 'Biden - 1', 'Biden - 1', 'Biden - 1'
$ term_label <str> '(2021)\nBiden', '(2021)\nBiden', '(2021)\nBiden', '(2021)\nBiden', '(2021)\nBiden', '(2021)\nBiden', '(2021)\nBiden', '(2021)\nBiden', '(2021)\nBiden', '(2021)\nBiden'
$ day_since_start <i64> 0, 1, 2, 5, 6, 7, 8, 13, 15, 21
$ signing_date <date> 2021-01-20, 2021-01-21, 2021-01-22, 2021-01-25, 2021-01-26, 2021-01-27, 2021-01-28, 2021-02-02, 2021-02-04, 2021-02-10
$ len <u32> 9, 8, 2, 2, 1, 2, 1, 3, 1, 1
$ n_cumul <u32> 9, 17, 19, 21, 22, 24, 25, 28, 29, 30
In [8]:
# plot not included in final; the first plot you make often isn't the best!
# for example, this one has censored data because (as of writing in 2025, Trump 2 is not complete)
('term_label').agg( pl.col('n_cumul').max() )) +
ggplot(df_cumul.group_by(= 'term_label', y = 'n_cumul', fill = 'term_label') +
aes(x +
geom_col() = 'Executive Orders Signed by Term', x = '', y = '') +
labs(title +
theme_538() 'qual', palette = 'Set1') +
scale_color_brewer(= 'none')
theme(legend_position )
In [9]:
(+
ggplot(df_cumul) = 'day_since_start', y = 'n_cumul', color = 'term_label') +
aes(x +
geom_line()
labs(= 'Executive Orders Signed by Days in Office',
title = 'Days since Term Start',
x = 'EOs Issued',
y = 'Term') +
color +
theme_538() 'qual', palette = 'Set1') +
scale_color_brewer(= 'bottom')
theme(legend_position )
In [10]:
= (
df_pit
df_cumul= pl.when( pl.col('signing_date') == pl.col('signing_date').max() )
.with_columns( max_dss 'day_since_start') )
.then( pl.col(None )
.otherwise( max()
.
)'term_label', 'max_dss')
.group_by(
.agg( = pl.when( pl.col('day_since_start') <= pl.col('max_dss') ).then(pl.col('n_cumul')).otherwise(None).max(),
n_ttl_pit = pl.col('n_cumul').max(),
n_ttl
)
.with_columns( = pl.when( pl.col('term_label') == pl.col('term_label').max())
n_ttl None)
.then('n_ttl')) )
.otherwise( pl.col('term_label')
.sort(
)
= df_pit.get_column('max_dss')[0]
n_days_in_office
(
GT(df_pit)'max_dss')
.cols_hide(
.tab_header(= 'Executive Orders Issued by Term',
title = f'Normalized for first {n_days_in_office} days in office' +
subtitle f' ({n_days_in_office * 100 / (365*4 + 1):.1f}% of term)')
.tab_spanner(="Count",
label= cs.contains("ttl")
columns
)
.cols_label(= 'Term',
term_label = 'Point in time',
n_ttl_pit = 'Full term'
n_ttl
)'center')
.cols_align(="-")
.sub_missing(missing_text
.opt_row_striping() )
Executive Orders Issued by Term | ||
---|---|---|
Normalized for first 184 days in office (12.6% of term) | ||
Term | Count | |
Point in time | Full term | |
(2005) Bush | 13 | 118 |
(2009) Obama | 22 | 148 |
(2013) Obama | 14 | 130 |
(2017) Trump | 42 | 220 |
(2021) Biden | 52 | 162 |
(2025) Trump | 174 | - |
I have some thoughts…