100일의 코드: 2022년을 위한 완전한 Python Pro 부트캠프 - 25일차(미국 주 게임)
main.py
# with open("weather_data.csv") as data_file:
# data = data_file.readlines()
# print(data)
# import csv
# with open("weather_data.csv") as data_file:
# data = csv.reader(data_file)
# for row in data:
# print(row)
# with open("weather_data.csv") as data_file:
# data = csv.reader(data_file)
# temperatures = []
# for row in data:
# if row[1] != "temp":
# temperatures.append(int(row[1]))
#
# print(temperatures)
import pandas
# data = pandas.read_csv("weather_data.csv")
# print(type(data))
# print(type(data["temp"]))
# data_dict = data.to_dict()
# # print(data_dict)
#
# temp_list = data["temp"].to_list()
# # print(len(temp_list))
#
# average = sum(temp_list) / len(temp_list)
# print(average)
#
# print(data["temp"].mean())
#
# print(data["temp"].max())
#
# # Get data in columns
# print(data["condition"])
# print(data.condition)
# Get data in the row
# print(data[data.day == "Monday"])
# print(data[data.temp == data.temp.max()])
# monday = data[data.day == "Monday"]
# print(monday.condition)
#
# monday = data[data.day == "Monday"]
# print(monday.temp)
#
# monday = data[data.day == "Monday"]
# temp_conv = (monday.temp * 1.8 + 32)
# print(temp_conv)
# Create a data frame from scratch
data_dict = {
"students": ["Amy", "James", "Angela"],
"scores": [76, 56, 65]
}
data = pandas.DataFrame(data_dict)
# print(data)
data.to_csv("new_data.csv")
weather_data.csv
day,temp,condition
Monday,12,Sunny
Tuesday,14,Rain
Wednesday,15,Rain
Thursday,14,Cloudy
Friday,21,Sunny
Saturday,22,Sunny
Sunday,24,Sunny
new_data.csv
,students,scores
0,Amy,76
1,James,56
2,Angela,65
main.py
# How many coloured squirrels per color
# Create a new csv with this data (squirrel_count.csv)
import pandas
data = pandas.read_csv("2018_Central_Park_Squirrel_Census_Squirrel_Data.csv")
gray_squirrels_count = len(data[data["Primary Fur Color"] == "Gray"])
red_squirrels_count = len(data[data["Primary Fur Color"] == "Cinnamon"])
black_squirrels_count = len(data[data["Primary Fur Color"] == "Black"])
print(gray_squirrels_count)
print(red_squirrels_count)
print(black_squirrels_count)
data_dict = {
"Fur Color": ["Gray", "Cinnamon", "Black"],
"Count": [gray_squirrels_count, red_squirrels_count, black_squirrels_count]
}
data_frame = pandas.DataFrame(data_dict)
data_frame.to_csv("squirrel_count.csv")
squirrel_count.csv
,Fur Color,Count
0,Gray,2473
1,Cinnamon,392
2,Black,103
2018_중앙_공원_다람쥐_Census_Squirrel_Data.csv
# download from https://data.cityofnewyork.us/Environment/2018-Central-Park-Squirrel-Census-Squirrel-Data/vfnx-vebw
main.py
import turtle
import pandas
screen = turtle.Screen()
screen.title("U.S States Game")
image = "blank_states_img.gif"
screen.addshape(image)
turtle.shape(image)
data = pandas.read_csv("50_states.csv")
all_states = data.state.to_list()
guessed_states = []
while len(guessed_states) < 50:
answer_state = screen.textinput(title=f"{len(guessed_states)}/50 States Correct",
prompt="Whats another state's name?").title()
if answer_state == "Exit":
missing_states = []
for state in all_states:
if state not in guessed_states:
missing_states.append(state)
new_data = pandas.DataFrame(missing_states)
new_data.to_csv("states_to_learn.csv")
break
if answer_state in all_states:
guessed_states.append(answer_state)
t = turtle.Turtle()
t.hideturtle()
t.penup()
state_date = data[data.state == answer_state]
t.goto(int(state_date.x), int(state_date.y))
t.write(answer_state)
state,x,y
Alabama,139,-77
Alaska,-204,-170
Arizona,-203,-40
Arkansas,57,-53
California,-297,13
Colorado,-112,20
Connecticut,297,96
Delaware,275,42
Florida,220,-145
Georgia,182,-75
Hawaii,-317,-143
Idaho,-216,122
Illinois,95,37
Indiana,133,39
Iowa,38,65
Kansas,-17,5
Kentucky,149,1
Louisiana,59,-114
Maine,319,164
Maryland,288,27
Massachusetts,312,112
Michigan,148,101
Minnesota,23,135
Mississippi,94,-78
Missouri,49,6
Montana,-141,150
Nebraska,-61,66
Nevada,-257,56
New Hampshire,302,127
New Jersey,282,65
New Mexico,-128,-43
New York,236,104
North Carolina,239,-22
North Dakota,-44,158
Ohio,176,52
Oklahoma,-8,-41
Oregon,-278,138
Pennsylvania,238,72
Rhode Island,318,94
South Carolina,218,-51
South Dakota,-44,109
Tennessee,131,-34
Texas,-38,-106
Utah,-189,34
Vermont,282,154
Virginia,234,12
Washington,-257,193
West Virginia,200,20
Wisconsin,83,113
Wyoming,-134,90
blank_states.img
Reference
이 문제에 관하여(100일의 코드: 2022년을 위한 완전한 Python Pro 부트캠프 - 25일차(미국 주 게임)), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://dev.to/mike_kameta_aed62d48c2d0f/100-days-of-code-the-complete-python-pro-bootcamp-for-2022-day-25-us-states-game-3n9j텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)