Apr-05-2019, 01:27 PM
Sorry for asking really simple questions. I've been trying for hours with no luck.
1. Print the number of unique stations
2. Print the most frequent station. Print out the number of times it appears in the list
whose keys are unique station and values are the corresponding counts computed from the dataset.
Print the dictionary.
that appears more than ten times in the dataset.
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)
Error:File "<ipython-input-69-fe0f4deaa23c>", line 9
print np.argmax(station)
^
SyntaxError: invalid syntax
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])
Error:<ipython-input-25-1761f5ad8e1d> in <module>
9 reader = csv.DictReader(csvfile)
10 for row in reader:
---> 11 print(row['STATION'], row[count])
12
13
NameError: name 'count' is not defined
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)
Error:if stations >10
^
SyntaxError: invalid syntax
Any advice would be amazing as I feel I am getting nowhere.