Bentley University CS 230
Python 编程代写 This program combines many topics we covered this semester as you create a store finder app for Starbucks locations.
Introduction to Programming with Python
Homework 7 – Starbucks Store Finder
Description Python 编程代写
This program combines many topics we covered this semester as you create a store finder app for Starbucks locations.
The program will implement a menu of options:
- Find Stores by City andState
- Find Stores within Distance ofCity
- Find Stores within Distance of ZipCode
- Quit
After selecting options 1, 2, or 3, ask the user to enter the desired information, and then ask whether to display all stores in the specified location area, or only those with drive through windows. If the user requests only drive through stores, display only those, otherwise display all of them.Python 编程代写
Your program will print information about stores in the specified location, and then show them visually on a map. Show stores with and without drive throughs using different colored map markers.
Data Python 编程代写
Use the list of Starbucks stores in the United States (from 2013) available from the Open Data site at socrata.com: https://opendata.socrata.com/Business/All-Starbucks-Locations-in-the-US/txu4-fsic Download and save it as CSV. Use a symbolic constant in your program to store the name of the file:
STARBUCKS_FILE = “All_Starbucks_Locations_in_the_US.csv”
Do not change the name of the file! You do not have to upload the data file when you submit your completed program. Submit only the Store Finder program.
Modules
Install these modules so that your Python environment has access to them:
- pandas (data analysistools)Python 编程代写
- geopy (geographytools)
- folium (mappingtools)
- uszipcode (zip codetools)
Classes
- Create a class called Store which contains at least a store’s ID, name, street address, city, state, zip, latitude, longitude, drive-thru (from the Features – Stations column, which has the value “Drive-Through” if the store has a drive through window), and distance (to be calculated, the store’sdistance from the user’s home location). Store a distance only if doing a distance
- Createa constructor (initializer) and a string method for this Use a default value of -1 if no distance value is available. The string method should return a string that neatly displays each attribute of the class. (Display the distance, formatted to two decimal places, when it is calculated. Only include the distance for a distance search (by city/state or zip code).Python 编程代写
- You don’t need to write any accessor or mutator methods for this
Functions
- Writea function getData() which reads the Starbucks data csv file into a pandas You can filter the DataFrame to contain only the columns we will be working with in this program. The method returns a DataFrame. You might use a symbolic constant to store that list (as a tuple):
FILTERS = (‘Number’, ‘Name’, ‘Street Address’, ‘City’, ‘State’, ‘Zip’,‘Latitude’,‘Longitude’,‘Features – Stations’)Python 编程代写
Doing so will help you iterate through the columns of the Data Frame elsewhere in your program.
- Write a function displayStores(dfStores) to display information for the stores contained in the Data Frame dfStores, passed in as a parameter. The function should create a Store object from each store in the data frame and use its string method to print it. (Or create a list of Stores and print the)
- Write a function displayMap(dfStores) which plots store information from a DataFrame dfStores on a map.Center the map at the average of the latitude and longitude coordinates. Use an appropriate method of the DataFrame class to calculate the average, don’t write your own average function. Use the folium module to create and display the map. Be sure each location has a title. Save the map info to an HTML file named html and launch a browser to display themap.Python 编程代写
-
Write a function findStoresByCityState(dfStores) which asks the user for the name of a city and state,
and then locates all of the stores in that city and state. This function should call displayMap and displayStores to display the stores on the map and in the console window. Note that the value for distance for each store in dfStores will be -1 because you’re not calculating a distance in this
- Writea function findStoresWithinDistanceCityState(dfStores) which asks the user for a number of miles and a home city location, then locates all of the stores within that mile radius of the home city. The code should add a new column to dfStores containing the distance between each store in the database and the specified city and state. This function should call displayMap and displayStores to display the stores on the map and in the console window.Python 编程代写
- Write a function findStoresWithinDistanceZip (dfStores) which asks the user for a radius of milesand a home city zip code, then locates all of the stores within that mile radius of the home city zip code. Read the documentation for the uszipcode module located at https://pypi.org/project/uszipcode/ (and install it) so you can add this capability. The code should add a new column to dfStores containing the distance between each store in the database and the specified zip code. This function should call displayMap and displayStores to display the stores on the map and in the console
- Write a main() function to implement the menu and program flow based on user
Error Checking Python 编程代写
- Write at least two try / except statements in your program to catch errors that might arise. Be sureto write a comment in your code about values or situations that would cause the program to crash if you didn’t include
One place where you can use this effectively is when creating a Store object in dfDisplay. The value for distance is found in row[9], but that column only exists when doing a distance search. When doing a city/state search, the data frame won’t have this column, so if you try to access it, you will get index out of range error.
- Displayappropriate error messages for invalid data, if no stores are found in the location that the user entered, and other
Extra Credit:
Add any of these features to the program for extra credit.
- Symbols on the Map: Read the documentation on the folium map class to figure out how to displaya symbol (such as a coffee cup) on the map Search online for how to add custom markers to a folium map in Python, or in a Python console window, type import folium and help(folium.Marker) to get complete documentation for the folium Marker class.Python 编程代写
- Add a Store: Add information about a new store to the DataFrame and save it to the csv file. You do not have to add all the fields, just the ones contained n your Store object. When writing it to the file, you can write blank values for the columns you
- Remove a Store: Ask the user to identify a store (by its location or store ID) to delete, remove it from the DataFrame, then write the updated contents to the CSV
Be sure to include print statements that display when the program runs, as well as comments in your code, identifying the additional features you added.
Code and Style Requirements
Start with the starbucks_starter.py file. Fill in the code that is missing.
For full credit, please follow these style requirements for this and future assignments.Python 编程代写
- Includeintroductory comments (docstrings) listing the name of the author, the date the file was created and a description of the purpose of the program. Also provide comments within the program code for any part of code that may be difficult to follow and would benefit from explanatory text. Add comments to major sections of the code so that you and other readers of your code can follow it
- Usevariable names that reflect the purpose of the variable and add comments if more information would be helpful (for example, units of measurement or valid values).
- Usesymbolic constants to represent the constant numbers mentioned above, so that if any of these numbers changes, only the constant would need to be modified to make your program produce the right When your program is graded, these numbers may be modified, and the program still must work.
- Your input/output format should be similar to the sample
- Wewill test your program using different questions and leaderboard files, so be sure they follow the file formats
Coding Hints:Python 编程代写
The best way to develop a program is by working on it incrementally and periodically verifying the correctness of each part as you go along. For instance, start by developing the code for the menu. Then add and test your code for each feature. Continue writing and testing one feature at a time until you have a completely working program.Python 编程代写
To organize your program more effectively, write functions for each menu option. Be sure to include a
main() function!
In addition to functions for each menu item, write as many helping functions as make sense for repeated tasks. As your program has many parts or tasks, please be sure that you comment what each section of your code is doing.
Grading:
- This assignment will be worth 8 % of your final
- Theinput and output of your program need to appear in exactly the order that is shown in the sample interaction
- Your program should compile without syntax errors to receive any credit. If a part of your programis working, you will receive partial credit, but only if the program compiles without syntax errors. As you program, I highly recommend that you save intermediate versions of the .py file each time you get a piece of the program running. This way you can always have something to submit that works on at least some of the Otherwise, what was
working at one point may no longer work after further edits, and you may have no idea how to go back to the previous version (this is all too common!)Python 编程代写
Submission:
- Nameyour script as py and upload it onto Blackboard by the deadline. Do not submit your map.html file or the Starbucks csv file.
Sample Run:
Option 1
*** Starbucks Store Finder ***
- – Find Stores by City andState
- – Find Stores within Distance ofCity
- – Find Stores within Distance of ZipCode
- -Quit
Enter your choice: 1
Enter a city: (enter to stop) Haverhill Enter a state abbreviation: MA
Show only stores with drive-thru? y/n: n
Option 3 Python 编程代写
*** Starbucks Store Finder ***
- – Find Stores by City andState
- – Find Stores within Distance of City andState
- – Find Stores within Distance of ZipCode
- -Quit
Enter your choice: 3 Search radius in miles: 5 Enter zip code: 60609
Only show stores with drive-thru? y/n n
28 Stores Found.
Etc.
*** Starbucks Store Finder ***
- – Find Stores by City andState
- – Find Stores within Distance of City andState
- – Find Stores within Distance of ZipCode
- -Quit
Enter your choice: 3
Start downloading data for simple zipcode database, total size 9MB …
1MB finished…
2MB finished…
3MB finished…
4MB finished…
5MB finished…
6MB finished…
7MB finished…
8MB finished…
9MB finished…
10MB finished…
Complete!
Search radius in miles: 4 Enter zip code: 01776 (42.39, -71.42)
Only show stores with drive-thru? y/nn
1 Stores Found.
Map located in: C:\Users\mfrydenberg\OneDrive\Python\S19- CS230\MiscCode\Pandas\map.html
其他代写:java代写 function代写 web代写 编程代写 report代写 数学代写 algorithm代写 python代写 code代写 project代写 dataset代写 analysis代写 C++代写 代写CS 金融经济统计代写 essay代写 assembly代写 program代写 数据分析代写