Hallo zusammen,
Ich habe eine Tabelle mit einigen Spalten. Zwei davon sind : 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
Meine Afgabe ist zu zählen, welche Kombination von den beiden (Start Station + End Station) am meisten vorkommen. Das ist mein erster Versuch:
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)
Leider habe das problem mit df2. Es kommt nicht der gewünschten Ergebnis raus
Ideen?
Vielen Dank!
Zwei Spalten kombinieren /Pandas
Code: Alles auswählen
df2 = (x+' & '+y)
Code: Alles auswählen
df2 = x+' & '+y
Ohne das ich die CSV genau kennen würde, denke ich ist es so besser
Code: Alles auswählen
x = "Bahnstation A"
y = "Bahnstation B"
df2 = "{} + {}".format(x,y) # Vor und Zwischen den Platzhaltern kann man schreiben was man Lustig ist. Zahlen etc sind auch möglich
print(df2) # Als Beispiel Output