forked from udacity/pdsnd_github
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcity_input.py
More file actions
25 lines (18 loc) · 800 Bytes
/
Copy pathcity_input.py
File metadata and controls
25 lines (18 loc) · 800 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import pandas as pd
CITY_DATA = { 'chicago': 'chicago.csv',
'new york city': 'new_york_city.csv',
'washington': 'washington.csv' }
user_input = input("Which cities information do you want? Enter: Chicago, Washington, New York: ")
try:
if user_input.lower() == ('new york'):
filename = ('new york city')
else:
filename = (user_input).lower()
except KeyError:
print("Sorry you did not enter a valid city")
df = pd.read_csv(CITY_DATA[filename])
df['Start Time'] = pd.to_datetime(df['Start Time'])
# extract month and day of week from Start Time to create new columns
df['month'] = pd.to_datetime(df['Start Time']).dt.month_name()
df['day of week'] = pd.to_datetime(df['Start Time']).dt.day_name()
print(df.head())