Skip to content

Instantly share code, notes, and snippets.

@smzn
Created January 7, 2024 01:20
Show Gist options
  • Save smzn/1d81c76f02b43e49bf6e99e5becfa7b2 to your computer and use it in GitHub Desktop.
Save smzn/1d81c76f02b43e49bf6e99e5becfa7b2 to your computer and use it in GitHub Desktop.
ステーション間のトリップの回数をカウント
# ステーション間のトリップの回数をカウント
transition_counts = df.groupby(['start_station_name', 'end_station_name']).size().reset_index(name='transition_count')
# 推移回数行列の作成
transition_matrix = transition_counts.pivot_table(index='start_station_name', columns='end_station_name', values='transition_count', fill_value=0)
# 結果を表示(上位の行のみ)
transition_matrix
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment