Skip to content

Instantly share code, notes, and snippets.

@brunojhovany
Last active September 10, 2022 07:51
Show Gist options
  • Save brunojhovany/b8acc01c78b3725ca302c4b37954cae5 to your computer and use it in GitHub Desktop.
Save brunojhovany/b8acc01c78b3725ca302c4b37954cae5 to your computer and use it in GitHub Desktop.
coderbyte age counting with python
## In this example i use python with pandas
import requests
import numpy as np
import pandas as pd
r = requests.get('https://coderbyte.com/api/challenges/json/age-counting%27')
print(len(r.json()['data']))
# split data by ", "
data = r.json()['data'].split(", ")
# Load to DataFrame
df = pd.DataFrame([sub.split("=") for sub in data],columns=['key', 'age'])
# Find all age values in column "key"
dfAge = df.loc[df['key'] == 'age']
# convert column values to int
dfAge['age'] = dfAge['age'].astype(int)
# find in age column all >= 50
dfAge = dfAge.loc[dfAge['age'] >= 50]
print(len(dfAge))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment