Skip to content

Instantly share code, notes, and snippets.

@luispedro
Last active September 13, 2024 12:46
Show Gist options
  • Save luispedro/4c0c89d0c1045ce764869d62b3caabeb to your computer and use it in GitHub Desktop.
Save luispedro/4c0c89d0c1045ce764869d62b3caabeb to your computer and use it in GitHub Desktop.
Steps in 2024
import pandas as pd
TARGET = 5_000_000
TARGET_RATE = TARGET / 366
data = [
('January', 31, 271_347),
('February', 29, 321_084),
('March', 31, 424_562),
('April', 30, 412_478),
('May', 31, 442_295),
('June', 30, 436_819),
('July', 31, 406_350),
('August', 31, 378_630),
('September', 7, 110_786),
]
data = pd.DataFrame(data, columns=['Month', 'Days', 'Steps'])
data['TotalSteps'] = data['Steps'].cumsum()
data['TotalDays'] = data['Days'].cumsum()
data['MonthRate'] = data.eval('(Steps/Days)/@TARGET_RATE')
data['Deficit'] = data.eval('TotalSteps - @TARGET_RATE * TotalDays').astype(int)
data['CummRate'] = data.eval('TotalSteps/TotalDays/@TARGET_RATE')
data['RelRate'] = data.eval('Steps/Days/( (@TARGET-TotalSteps+Steps)/(366-TotalDays+Days) )')
total_needed = TARGET - data['TotalSteps'].iloc[-1]
days_to_go = 366 - data['TotalDays'].iloc[-1]
rate_needed = total_needed / days_to_go
data.index = data.apply(lambda x: f"{x['Month']}" if x['Days'] > 28 else f"{x['Month']} ({x['Days']}d)", axis=1)
data = data.drop(columns=['Month', 'Days', 'TotalDays'])
data['Steps'] //= 100
data['Steps'] /= 10
data['Total steps (k)'] = data.eval('TotalSteps/1000').astype(int).map('{:,}'.format)
data['Deficit'] //= 1000
data.style.format("{:.1f}")
data.rename(columns=
{ 'Steps': 'Steps (k)',
'Deficit': 'Deficit (k)',
}, inplace=True)
data['Month rate'] = data['MonthRate'].map('{:.1%}'.format)
data['Cumm rate'] = data['CummRate'].map('{:.1%}'.format)
data['Rate needed'] = data['RelRate'].map('{:.1%}'.format)
pd.set_option('display.width', 120)
print(data[['Steps (k)', 'Total steps (k)', 'Deficit (k)', 'Month rate', 'Cumm rate', 'Rate needed']])
print(f'Deficit to catch up: {data["Deficit (k)"].iloc[-1]}k')
print(f'Rate per day needed for rest of year: {rate_needed:,.6}')
@luispedro
Copy link
Author

ENH Update step counts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment