• Skip to main content
  • Skip to primary sidebar

学習記録

DataFrame カラムの名称が異なるが意味が同じデータを繋げる

2017年11月26日 by 河副 太智 Leave a Comment

 pandas.merge(左側DF, 右側DF, left_on=”左側DFのカラム”,
right_on=”右側DFのカラム”, how=”結合方法”)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import pandas as pd
​
# 注文情報
order_df = pd.DataFrame([[1000, 2546, 103],
                         [1001, 4352, 101],
                         [1002, 342, 101]],
                         columns=["id", "item_id", "customer_id"])
# 顧客情報
customer_df = pd.DataFrame([[101, "Tanaka"],
                           [102, "Suzuki"],
                           [103, "Kato"]],
                           columns=["id", "name"])
​
# customer_dfを元に"name"をorder_dfに結合してorder_dfに代入してください
order_df = pd.merge(order_df,customer_df,left_on="customer_id",right_on="id",how="inner")
​
print(order_df)

 

1
2
3
4
   id_x  item_id  customer_id  id_y    name
0  1000     2546          103   103    Kato
1  1001     4352          101   101  Tanaka
2  1002      342          101   101  Tanaka
このエントリーをはてなブックマークに追加

Tweet
[`yahoo` not found]
このエントリーを Google ブックマーク に追加
LinkedIn にシェア
LINEで送る


Filed Under: Numpy, Pandas

Reader Interactions

コメントを残す コメントをキャンセル

メールアドレスが公開されることはありません。 ※ が付いている欄は必須項目です

Primary Sidebar

カテゴリー

  • AWS
  • Bootstrap
  • Dash
  • Django
  • flask
  • GIT(sourcetree)
  • Plotly/Dash
  • VPS
  • その他tool
  • ブログ
  • プログラミング
    • Bokeh
    • css
    • HoloViews
    • Jupyter
    • Numpy
    • Pandas
    • PosgreSQL
    • Python 基本
    • python3
      • webアプリ
    • python3解説
    • scikit-learn
    • scipy
    • vps
    • Wordpress
    • グラフ
    • コマンド
    • スクレイピング
    • チートシート
    • データクレンジング
    • ブロックチェーン
    • 作成実績
    • 時系列分析
    • 機械学習
      • 分析手法
      • 教師有り
    • 異常値検知
    • 自然言語処理
  • 一太郎
  • 数学
    • sympy
      • 対数関数(log)
      • 累乗根(n乗根)
    • 暗号学

Copyright © 2025 · Genesis Sample on Genesis Framework · WordPress · Log in