{
  "id": 75850,
  "title": "Creating Aggregate Features from Merchants",
  "url": "/competitions/elo-merchant-category-recommendation/discussion/75850",
  "author_name": "",
  "post_date": "2018-12-27T05:38:12.115571100Z",
  "votes": null,
  "comment_count": 2,
  "views": 0,
  "content": "<p>How are y'all creating aggregate features from the merchants file? From my understanding <em>train.csv</em> contains a <code>card_id</code> which is the join key for the <em>historical_transactions.csv</em> file which also contains a <code>card_id</code> column. This is easy enough to aggregate, just <code>historical_transactions.groupby([\"card_id\"])[\"purchase_amount\"].agg(np.mean)</code> or whatever. However, the <em>historical_transactions.csv</em> file also contains a join key for the <em>merchants.csv</em> file with the <code>merchant_id</code> column in both files, which means it's not as easy to create aggregate features from the <em>merchants.csv</em> file. So my question is how are y'all doing a 3 table join (<em>train</em> &lt;-&gt; <em>historical_transactions</em> &lt;-&gt; <em>merchants</em>)? I think my primary issue is that I'm not familiar enough with pandas yet to know how to do this so any help would be greatly appreciated! Thanks!</p>",
  "messages": [
    {
      "id": "445845",
      "postDate": "12/27/2018 05:38:12",
      "content": "<p>How are y'all creating aggregate features from the merchants file? From my understanding <em>train.csv</em> contains a <code>card_id</code> which is the join key for the <em>historical_transactions.csv</em> file which also contains a <code>card_id</code> column. This is easy enough to aggregate, just <code>historical_transactions.groupby([\"card_id\"])[\"purchase_amount\"].agg(np.mean)</code> or whatever. However, the <em>historical_transactions.csv</em> file also contains a join key for the <em>merchants.csv</em> file with the <code>merchant_id</code> column in both files, which means it's not as easy to create aggregate features from the <em>merchants.csv</em> file. So my question is how are y'all doing a 3 table join (<em>train</em> &lt;-&gt; <em>historical_transactions</em> &lt;-&gt; <em>merchants</em>)? I think my primary issue is that I'm not familiar enough with pandas yet to know how to do this so any help would be greatly appreciated! Thanks!</p>",
      "rawMarkdown": "How are y'all creating aggregate features from the merchants file? From my understanding *train.csv* contains a `card_id` which is the join key for the *historical\\_transactions.csv* file which also contains a `card_id` column. This is easy enough to aggregate, just `historical_transactions.groupby([\"card_id\"])[\"purchase_amount\"].agg(np.mean)` or whatever. However, the *historical\\_transactions.csv* file also contains a join key for the *merchants.csv* file with the `merchant_id` column in both files, which means it's not as easy to create aggregate features from the *merchants.csv* file. So my question is how are y'all doing a 3 table join (*train* &lt;-&gt; *historical\\_transactions* &lt;-&gt; *merchants*)? I think my primary issue is that I'm not familiar enough with pandas yet to know how to do this so any help would be greatly appreciated! Thanks!",
      "votes": null
    },
    {
      "id": "446176",
      "postDate": "12/27/2018 16:44:11",
      "content": "<p>Hello, I believe you can join historical transactions with merchants , using card_id, do your feature engineering at card_id level. Once done , you can join with train with card_id. Train csv contains one row per card_id, so that should not pose any problems. I did that way. Let me know if this works.</p>",
      "rawMarkdown": "Hello, I believe you can join historical transactions with merchants , using card_id, do your feature engineering at card_id level. Once done , you can join with train with card_id. Train csv contains one row per card_id, so that should not pose any problems. I did that way. Let me know if this works.",
      "votes": null
    },
    {
      "id": "446287",
      "postDate": "12/27/2018 20:05:28",
      "content": "<p>That did the trick. Thanks!</p>",
      "rawMarkdown": "That did the trick. Thanks!",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 446176,
      "author_name": "anirbank",
      "author_url": "",
      "post_date": "12/27/2018 16:44:11",
      "content": "<p>Hello, I believe you can join historical transactions with merchants , using card_id, do your feature engineering at card_id level. Once done , you can join with train with card_id. Train csv contains one row per card_id, so that should not pose any problems. I did that way. Let me know if this works.</p>",
      "votes": null,
      "replies": [
        {
          "id": 446287,
          "author_name": "timothycwillard",
          "author_url": "",
          "post_date": "12/27/2018 20:05:28",
          "content": "<p>That did the trick. Thanks!</p>",
          "votes": null,
          "replies": []
        }
      ]
    }
  ],
  "raw_markdown_by_id": {
    "445845": "How are y'all creating aggregate features from the merchants file? From my understanding *train.csv* contains a `card_id` which is the join key for the *historical\\_transactions.csv* file which also contains a `card_id` column. This is easy enough to aggregate, just `historical_transactions.groupby([\"card_id\"])[\"purchase_amount\"].agg(np.mean)` or whatever. However, the *historical\\_transactions.csv* file also contains a join key for the *merchants.csv* file with the `merchant_id` column in both files, which means it's not as easy to create aggregate features from the *merchants.csv* file. So my question is how are y'all doing a 3 table join (*train* &lt;-&gt; *historical\\_transactions* &lt;-&gt; *merchants*)? I think my primary issue is that I'm not familiar enough with pandas yet to know how to do this so any help would be greatly appreciated! Thanks!",
    "446176": "Hello, I believe you can join historical transactions with merchants , using card_id, do your feature engineering at card_id level. Once done , you can join with train with card_id. Train csv contains one row per card_id, so that should not pose any problems. I did that way. Let me know if this works.",
    "446287": "That did the trick. Thanks!"
  },
  "source": "meta"
}