Skip to content

Commit f651642

Browse files
Andres ScharifkerAndres Scharifker
Andres Scharifker
authored and
Andres Scharifker
committed
added fruits project
1 parent e2a1e77 commit f651642

File tree

7 files changed

+152
-0
lines changed

7 files changed

+152
-0
lines changed

Diff for: .DS_Store

6 KB
Binary file not shown.

Diff for: fruits/desired_fruits.csv

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
fruit
2+
apple
3+
avocado
4+
tomato
5+
peach
6+
grape
7+
papaya
8+
apricot

Diff for: fruits/fruit_transactions.csv

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Name,Date,Fruit
2+
Tiffany Sosa,2024/08/28,Grape
3+
Tiffany Sosa,2024/08/28,Grape
4+
Richard Blackwell,2024/11/20,Apple
5+
Izaiah Donovan,2024/08/20,Apple
6+
Tara Murphy,2024/02/23,Grape
7+
Dashawn Alexander,2024/03/17,Banana
8+
Dashawn Alexander,2023/03/17,Banana
9+
Issac Gregory,2024/02/08,Avocado
10+
Keira Strickland,2024/02/04,Banana
11+
Dangelo Dyer,2023/09/17,Apple
12+
Reese Schultz,2023/06/21,Avocado
13+
Thaddeus Schneider,2024/12/09,Grape
14+
Anton Valentine,2023/10/09,Avocado
15+
Trevin Maxwell,2023/08/18,Pomegranate
16+
Annalise Cook,2024/08/17,Apple
17+
Devyn Mcbride,2023/11/16,Avocado
18+
Blaine Maldonado,2023/05/18,Apple
19+
Aden Phillips,2024/08/16,Pomegranate
20+
Brooke Bolton,2023/03/27,Avocado

Diff for: fruits/fruits1.py

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import requests
2+
import json
3+
import pandas as pd
4+
5+
url = 'https://www.fruityvice.com/api/fruit/all'
6+
7+
response = requests.get(url)
8+
9+
if response.status_code == 200:
10+
data = response.json()
11+
df = pd.DataFrame(data)
12+
df.set_index("name", inplace=True)
13+
14+
else:
15+
print("somethings off")
16+
17+
top_calories = df["nutritions"].str["calories"].nlargest(10)
18+
top_sugar = df["nutritions"].str["sugar"].nlargest(10)
19+
20+
joined = pd.concat([top_calories, top_sugar], axis = 'columns',keys=["Calories","Sugar"], join='inner').sort_values("Calories", ascending=False)
21+
22+
print(joined)

Diff for: fruits/fruits2.py

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import pandas as pd
2+
import requests
3+
import json
4+
5+
transactions = pd.read_csv("fruit_transactions.csv", parse_dates=["Date"])
6+
# print(transactions)
7+
8+
url = 'https://www.fruityvice.com/api/fruit/all'
9+
response = requests.get(url)
10+
desired_fruits = pd.read_csv("desired_fruits.csv")["fruit"].str.title()
11+
12+
if response.ok:
13+
data = response.json()
14+
df = pd.DataFrame(data)
15+
df.set_index('name', inplace=True)
16+
merged_df = df[df.index.isin(desired_fruits)]
17+
# print(merged_df)
18+
else:
19+
print("something wrong")
20+
21+
person_fruit_attributes = transactions.merge(df, how='left', left_on="Fruit", right_index=True).sort_values("Name")
22+
23+
person_fruit_attributes['Calories'] = person_fruit_attributes['nutritions'].str['calories']
24+
person_fruit_attributes['Sugar'] = person_fruit_attributes['nutritions'].str['sugar']
25+
person_fruit_attributes.drop(['nutritions'],axis = 1,inplace=True)
26+
person_fruit_attributes = person_fruit_attributes[['Name','Date','Fruit','Calories','Sugar']]
27+
28+
# Create the group by object
29+
person = person_fruit_attributes.groupby('Name')
30+
# Create the aggregation
31+
intake_per_person = person[['Sugar','Calories']].sum().sort_values("Sugar", ascending=False)
32+
33+
top_eater = intake_per_person.nlargest(1,columns=['Sugar'])
34+
35+
36+
print(top_eater)

Diff for: fruits/fruits3.py

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import pandas as pd
2+
import requests
3+
4+
url = 'https://www.fruityvice.com/api/fruit/all'
5+
response = requests.get(url)
6+
7+
def extract_values(dictionary):
8+
Calories = dictionary['calories']
9+
Sugar = dictionary['sugar']
10+
return Calories, Sugar
11+
12+
if response.ok:
13+
#Fruits
14+
json_data = response.json()
15+
fruits = pd.DataFrame(json_data)
16+
fruits.set_index('name', inplace=True)
17+
fruits[['Calories', 'Sugar']] = fruits['nutritions'].apply(lambda x: pd.Series(extract_values(x)))
18+
fruits = fruits[["Calories","Sugar"]]
19+
20+
person = pd.read_csv("fruit_transactions.csv", parse_dates=["Date"])
21+
person['YrMonth'] = person['Date'].dt.strftime('%Y%m')
22+
person_fruit = person.merge(fruits, how='left', left_on='Fruit', right_index=True)
23+
person_fruit_agg = person_fruit.groupby(['Name','YrMonth'])
24+
person_fruit_agg = person_fruit_agg[['Calories','Sugar']].sum()
25+
# measure = input(" Which Metric do you want to filter by: ")
26+
print(person_fruit_agg)
27+
# print(person_fruit_agg.nlargest(1,measure))
28+
29+
30+
31+
32+
33+

Diff for: fruits/projects.txt

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
1)
2+
- Bring in all of them
3+
- put them in a dataframe
4+
- filter to the top 10 by calories
5+
- filter to the top 10 by sugar
6+
- find the ones in common
7+
8+
9+
2)
10+
- Have a CSV with the desired fruits
11+
- Only bring in the desired fruits
12+
- Have a CSV with transactions (John Jan 1 Apple for lots of names)
13+
- Find the person who ate the most calories
14+
15+
3)
16+
- Have a CSV with the desired fruits
17+
- Only bring in the desired fruits
18+
- Have a CSV with transactions (John Jan 1 Apple for lots of names)
19+
- Have a class with an attribute called largest consumer and never consumed where the user can input a fruit and the program returns the list of people.
20+
21+
22+
4)
23+
- Connect to PostgresSQL
24+
- Load the data from 2)
25+
- Do some querying
26+
27+
28+
4)
29+
- Use Airflow to load the data to Postgres on a schedule
30+
31+
32+
5)
33+
- Do it with ubuntu in Github?

0 commit comments

Comments
 (0)