Tried everything - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Homework (https://python-forum.io/forum-9.html) +--- Thread: Tried everything (/thread-17297.html) |
Tried everything - Confused - Apr-05-2019 Sorry for asking really simple questions. I've been trying for hours with no luck. 1. Print the number of unique stations import numpy as np data=pd.read_csv('train_station_routes.csv') station = np.array(data['STATION']) def unique(station): x = np.array(station) print(np.unique(x))When I ran the code nothing happened 2. Print the most frequent station. Print out the number of times it appears in the list import numpy as np data=pd.read_csv('train_station_routes.csv') station = np.array(data['STATION']) print np.argmax(station) 3.Write your code to construct a dictionary variable: ***station_popularity*** whose keys are unique station and values are the corresponding counts computed from the dataset. Print the dictionary. import csv with open('train_station_routes.csv') as csvfile: reader = csv.DictReader(csvfile) for row in reader: print(row['STATION'], row[count]) 4. Write your code to find and print out the list of stations that appears more than ten times in the dataset. import numpy as np data=pd.read_csv('train_station_routes.csv') stations = np.array(data['STATION']) if stations >10 print (stations) Any advice would be amazing as I feel I am getting nowhere.
RE: Tried everything - Yoriz - Apr-05-2019
RE: Tried everything - ichabod801 - Apr-05-2019 I think the problem with #3 is that count should be 'count' (that is, a string instead of a variable name). RE: Tried everything - Confused - Apr-05-2019 No unfortunately still not working with those changes :( RE: Tried everything - Yoriz - Apr-05-2019 ? Cannot help with Quote:still doesn't work Show the code you tried in code tags and explain what you expect to happen and what is actually happening and any errors received in error tags. Also the contents of 'train_station_routes.csv' is unknown. RE: Tried everything - Confused - Apr-05-2019 Question 4. Thanks
RE: Tried everything - Yoriz - Apr-05-2019 Try changing np.where(int(a) > 10)to np.where(np.int_(a) > 10) |