foodPlans module¶
- foodPlans.foodPlansmain()[source]¶
This function scrapes the USDA website for the most recent food plans and returns the weekly and monthly cost of each plan
These food plans are at a federal level, so it doesn’t change for different counties.
- The function returns @fused_df, a polars dataframewith the following columns:
Cohorts Age Age Cohort Thrifty Monthly Low Monthly M Moderate Monthly Liberal Monthly
Representing the monthly costs for different food plans divided by age group and cohort
- foodPlans.fuse_food_plans(thrifthy_plan, low_to_lib_plan)[source]¶
Fuse two DataFrames from the thrifty and low-to-liberal food plans into one.
- Parameters:
thrifthy_plan (polars.DataFrame) – A DataFrame with columns ‘Age’, ‘Weekly cost’, and ‘Monthly cost’ for the thrifty plan.
low_to_lib_plan (polars.DataFrame) – A DataFrame with columns ‘Age’, ‘Weekly cost low’, ‘Weekly cost moderate’, ‘Weekly cost liberal’, ‘Monthly cost low’, ‘Monthly cost moderate’, and ‘Monthly cost liberal’ for the low-to-liberal plan.
- Returns:
A DataFrame with columns ‘Cohorts’, ‘Age’, ‘Age Cohort’, ‘Thrifty Monthly’, ‘Low Monthly’, ‘Moderate Monthly’, and ‘Liberal Monthly’.
- Return type:
polars.DataFrame
- foodPlans.getAgeCohortMeans(df)[source]¶
Calculate the mean of each food plan for each age group.
- Parameters:
df (polars.DataFrame) – A DataFrame with columns ‘Age’, ‘Age Cohort’, ‘Thrifty Monthly’, ‘Low Monthly’, ‘Moderate Monthly’, and ‘Liberal Monthly’ for the fused food plans.
- Returns:
A DataFrame with columns ‘Age Cohort’, ‘Thrifty’, ‘Low’, ‘Moderate’, and ‘Liberal’ with the mean of each food plan for each age group.
- Return type:
polars.DataFrame
- foodPlans.getLowLiberalTable(linkToLowLiberalPlan)[source]¶
This function takes a link to the most recent low-liberal plan and returns a polars DataFrame with the following columns:
Age, Weekly cost low, Weekly cost moderate, Weekly cost liberal, Monthly cost low, Monthly cost moderate, Monthly cost liberal
- Columns can be referenced as dictionary keys, so for example, to print the weekly low cost of the moderate plan you do:
print(low_to_liberaldf[‘Weekly cost low’])
- And you can also get the nth value of a column by using its index:
print(low_to_liberaldf[‘Weekly cost low’][0])
- foodPlans.getThriftyTable(linkToThriftyPlan)[source]¶
This function takes a link to the most recent thrifty plan and returns a polars DataFrame with the following columns:
Age-sex group, Weekly cost, Monthly cost
- Columns can be referenced as dictionary keys, so for example, to print the weekly cost of the thrifty plan you do:
print(thrifthy_plan[‘Weekly cost’])
- And you can also get the nth value of a column by using its index:
print(thrifthy_plan[‘Weekly cost’][0])
- foodPlans.splitCostList1(numberList)[source]¶
Split a string of numbers with dollar signs into a list of floats.
- Parameters:
numberList (str) – A string of numbers with dollar signs, separated by newlines.
- Returns:
A list of floats.
- Return type:
list
Examples
>>> splitCostList1('$7.80\n$8.90') <<< [7.8, 8.9]
- foodPlans.splitGroupList1(groupList)[source]¶
Splits a string of age group labels into a list of individual age ranges.
- Parameters:
groupList (str) – A string containing age group labels separated by newlines, with an “Individual” label at the start.
- Returns:
A list containing age ranges for child, male, and female groups, excluding headers.
- Return type:
list
Examples
>>> splitGroupList1('Individuals\nChild Header\nChild 1\nChild 2\n...') <<<['Child 1', 'Child 2', ...']