Skip to content

Instantly share code, notes, and snippets.

@evanlh
Last active April 10, 2017 03:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save evanlh/0bad88fe48e71bd1244381dde75a1433 to your computer and use it in GitHub Desktop.
Save evanlh/0bad88fe48e71bd1244381dde75a1433 to your computer and use it in GitHub Desktop.
reader2.py
# Importing CSV
import pandas as pd
df = pd.read_csv('QuickSearch.csv', delimiter=',')
print df.head(0)
# What columns are not relevant and removing them
input = raw_input("Which columns would you like to delete(no spaces after comma): ")
input_list = input.split(',')
for column in input_list:
del df[column]
#What rows are not relevant and removing them
cities = raw_input("What Cities would you like to look at? ")
cities_list = cities.split(',')
#city_pos = df.columns.get_loc("City")
df = df[df['City'].isin(cities_list)]
# Re above, couldn't get something to work where you're iterating
# over the dataset & explicitly modifying the value of the row. The above
# syntax seems like the way you're supposed to filter values in
# a DataFrame while keeping it as a DataFrame. I think the other method
# would have worked if you did something like:
# rows = []
# for (i, r) in df.iterrows():
# row_dict = r.to_dict()
# if row_dict['City'] in cities_list:
# rows.append(row_dict)
#
# Of course the problem with the above is now all your filtered rows
# are in that rows variable as a list of dict's & you would have to
# either convert it back to a DataFrame or work with all rows in the future
# within that list. The DataFrame syntax is a little more obscure but
# seems a bit more powerful too.
# Don't see timeshare column in dataset? -elh
# timeshare = raw_input("Would you like to remove timeshares? Y/N")
# timeshare_pos = df.columns.get_loc("Timeshare")
## Pull Listings, get unique and Print possible entries
listings = df.ix[:,'Status'].unique()
print listings
## remove unwanted listings
status = raw_input("Which of the would you like to use? ")
status_list = status.split(',')
#status_pos = df.columns.get_loc("Status")
df = df[df['Status'].isin(status_list)]
print df
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment