Last active
September 10, 2022 07:51
-
-
Save brunojhovany/b8acc01c78b3725ca302c4b37954cae5 to your computer and use it in GitHub Desktop.
coderbyte age counting with python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## 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