day 25 - US states game
This commit is contained in:
54
025/task.py
Normal file
54
025/task.py
Normal file
@ -0,0 +1,54 @@
|
||||
# data = []
|
||||
# with open("weather_data.csv") as f:
|
||||
# for line in f.readlines():
|
||||
# data.append(line.strip().split(','))
|
||||
|
||||
# print(data)
|
||||
|
||||
# ------------------------------------------------------------------------
|
||||
# import csv
|
||||
|
||||
# temperatures = []
|
||||
# with open("weather_data.csv") as f:
|
||||
# reader = csv.reader(f)
|
||||
# next(reader)
|
||||
|
||||
# for row in reader:
|
||||
# temperatures.append(int(row[1]))
|
||||
|
||||
# print(temperatures)
|
||||
|
||||
# ------------------------------------------------------------------------
|
||||
|
||||
# import pandas as pd
|
||||
|
||||
# data = pd.read_csv("weather_data.csv", delimiter=",")
|
||||
# print(data["temp"].mean())
|
||||
# print(data["temp"].max())
|
||||
|
||||
# output = data[data.temp == data.temp.max()]
|
||||
# print(output)
|
||||
|
||||
# ------------------------------------------------------------------------
|
||||
|
||||
import pandas as pd
|
||||
|
||||
data = pd.read_csv("squirrels.csv")
|
||||
|
||||
colors = data["Primary Fur Color"].unique()
|
||||
|
||||
output_colors = []
|
||||
output_count = []
|
||||
for color in colors:
|
||||
if type(color) != str:
|
||||
continue
|
||||
count = len(data[data["Primary Fur Color"] == color])
|
||||
|
||||
output_colors.append(color)
|
||||
output_count.append(count)
|
||||
|
||||
output = {"color": output_colors, "count": output_count}
|
||||
|
||||
df = pd.DataFrame(output)
|
||||
|
||||
print(df.to_csv(index=False))
|
||||
Reference in New Issue
Block a user