Python Forum
Filtering by city /Question by beginner
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Filtering by city /Question by beginner
#2
indentation is mess line 13,14,15.
get_filters() function dos not make sense.
It shall be one blank line between functions.
Can be written like this.
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 city_choice():
    city = input('Would you like to see data for Chicago, New York, or Washington? ')
    return CITY_DATA.get(city, 'No data')

def load_data(city_choice):
    city = city_choice()
    if city == 'No data':
        return 'No city data for input given'
    else:
        df = pd.read_csv(city)
        return df.head()

if __name__ == '__main__':
     print(load_data(city_choice))
Reply


Messages In This Thread
RE: Filtering by city /Question by beginner - by snippsat - May-16-2018, 12:02 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Weather info using user api and city id Vimala 9 5,671 Jun-15-2018, 08:30 PM
Last Post: volcano63

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020