Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Tried everything
#1
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)
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.
Reply


Messages In This Thread
Tried everything - by Confused - Apr-05-2019, 01:27 PM
RE: Tried everything - by Yoriz - Apr-05-2019, 01:51 PM
RE: Tried everything - by ichabod801 - Apr-05-2019, 02:07 PM
RE: Tried everything - by Confused - Apr-05-2019, 03:13 PM
RE: Tried everything - by Yoriz - Apr-05-2019, 03:20 PM
RE: Tried everything - by Confused - Apr-05-2019, 04:25 PM
RE: Tried everything - by Yoriz - Apr-05-2019, 05:13 PM

Forum Jump:

User Panel Messages

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