May-12-2018, 03:03 PM
(This post was last modified: May-12-2018, 03:03 PM by Jack_Sparrow.)
Hi guys,
I have one table with a lot of columns: Two of them are Start Station and End Station
Start Station
0 Columbus Dr & Randolph St
1 Kingsbury St & Erie St
2 Canal St & Madison St
3 Spaulding Ave & Armitage Ave
4 Clark St & Randolph St
End Station \
Federal St & Polk St
Orleans St & Merchandise Mart Plaza
Paulina Ave & North Ave
California Ave & Milwaukee Ave
Financial Pl & Congress Pkwy
Now I want to display the most frequent combination of start station and end station trip
This is my code:
This is what I get
Columbus Dr & Randolph St & Federal St & Polk St 8
How can I fix it?
Thanks
J
I have one table with a lot of columns: Two of them are Start Station and End Station
Start Station
0 Columbus Dr & Randolph St
1 Kingsbury St & Erie St
2 Canal St & Madison St
3 Spaulding Ave & Armitage Ave
4 Clark St & Randolph St
End Station \
Federal St & Polk St
Orleans St & Merchandise Mart Plaza
Paulina Ave & North Ave
California Ave & Milwaukee Ave
Financial Pl & Congress Pkwy
Now I want to display the most frequent combination of start station and end station trip
This is my code:
import pandas as pd df = pd.read_csv('chicago.csv') # I exctract the column with start stations: x= df.iloc[:, 3] # I exctract the column with end stations: y =df.iloc[:, 4] # Put this two columns together and df2 = (x+' & '+y) #display the most frequent combination of start station and end station trip df1 = df.groupby(df2).count().sorted(df2) print (df1)However, the code doesn't work.
This is what I get
'DataFrame' object has no attribute 'sorted'Actually I excpected smth like this:
Columbus Dr & Randolph St & Federal St & Polk St 8
How can I fix it?
Thanks
J