May-15-2018, 06:47 PM
(This post was last modified: May-15-2018, 06:47 PM by Jack_Sparrow.)
Hi there,
I have a task:
I have 3 different csv files (chicago.csv, ney_york.csv and washington csv.) All three files have the same columns with different data. Now I want to ask user (using python) which state do she/he want to see?
Example:
'Would you like to see data for Chicago, New York, or Washington?'
The user's answer:
Chicago
If the user chooses one state, that is mean the files will be filtered in the background for this state:
This is my code:
I have a task:
I have 3 different csv files (chicago.csv, ney_york.csv and washington csv.) All three files have the same columns with different data. Now I want to ask user (using python) which state do she/he want to see?
Example:
'Would you like to see data for Chicago, New York, or Washington?'
The user's answer:
Chicago
If the user chooses one state, that is mean the files will be filtered in the background for this state:
This is my code:
import time import pandas as pd import numpy as np CITY_DATA = { 'Chicago': 'chicago.csv', 'New York city': 'new_york_city.csv', 'Washington': 'washington.csv' } def get_filters(): cities = ('Chicago', 'New York', 'Washington') city = None while city not in cities: city = input('Would you like to see data for Chicago, New York, or Washington? ') def load_data(city): print(CITY_DATA) df = pd.read_csv(CITY_DATA[city]) return df def main(): while True: city #For weekday df = load_data(city)And now I got stuck: I don't know how to write filtering for cities? Any ideas?