{
  "id": 5594,
  "title": "Number of Train/Test Cases? (nested CSV issues)",
  "url": "/competitions/facebook-recruiting-iii-keyword-extraction/discussion/5594",
  "author_name": "",
  "post_date": "2013-08-30T21:43:43.307Z",
  "votes": null,
  "comment_count": 9,
  "views": 3633,
  "content": "<p>Does anyone have a definitive count on train and test cases?<br>It seems as there might be some nested CSV data that's causing some unintended parsing.</p>",
  "messages": [
    {
      "id": "29809",
      "postDate": "08/30/2013 21:43:43",
      "content": "<p>Does anyone have a definitive count on train and test cases?<br>It seems as there might be some nested CSV data that's causing some unintended parsing.</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "29812",
      "postDate": "08/30/2013 22:27:27",
      "content": "<p>The sample count should align with the Ids (starts at 1 in the train set and ends with&nbsp;8047532 in the test set).</p>\n<p>This is a <strong><em>beast</em></strong> of a csv file, so we expect there to be a teething period and possibly some nasty edge cases. &nbsp;Bear with us if the dataset has &nbsp;bugs within.</p>\n<p>Mac users - you may have to use a program like Keka if the default unzipping &nbsp;does not spit out a csv file for Train.zip.</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "29813",
      "postDate": "08/30/2013 22:42:53",
      "content": "<p>There's a few really nasty cases involving MATLAB data and code, it's mostly just nested \\n and &quot; that throw things for a loop. Maybe URL encoding them, or using a uniquely guaranteed separator instead of &quot;field&quot;,&quot;field&quot;? I.e. remove all ~ from content, then use ~ as separators.<br><br>It might also be worthwhile to include a sample_train.csv and sample_test.csv, so participants can preview the data without potentially locking up slower (or virtual) machines.</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "29814",
      "postDate": "08/30/2013 22:44:44",
      "content": "<p>[quote=William Cukierski;29812]Mac users - you may have to use a program like Keka if the default unzipping &nbsp;does not spit out a csv file for Train.zip.[/quote]</p>\n<p>Archiver.app seems to work. Produces:</p>\n<p>MD5 (Train.csv) = 880a8869d61bcce1f26072d9f4797cb9</p>\n<p>MD5 (Test.csv) = cac7cb73cf4061d8f74f9b5a094e66ab</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "29815",
      "postDate": "08/30/2013 22:47:19",
      "content": "<p>Adrian:</p>\n<p>I'm sure you know this, but just for the record a simple one-liner like</p>\n<p><code>head -n [number of lines] Train.csv &gt; sample_train.csv</code></p>\n<p>should do just that.</p>\n<p>&nbsp;</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "29817",
      "postDate": "08/30/2013 23:18:02",
      "content": "<p>Archiver didn't quite work for me, for a reason, the following did:</p>\n<p>&nbsp;</p>\n<p><code>&nbsp;$ sudo port install p7zip<br></code><code>&nbsp;$ 7za x Train.zip<br></code></p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "29840",
      "postDate": "08/31/2013 11:36:03",
      "content": "<p>[quote=Rohit Sivaprasad;29815]</p>\n<p><code>head -n [number of lines] Train.csv &gt; sample_train.csv</code></p>\n<p>[/quote]</p>\n<p>Had no idea you could do this, thanks!</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "29853",
      "postDate": "08/31/2013 15:31:44",
      "content": "<p>Unfortunately, traditional line based Unix tools for working with text files like head, tail, wc, etc., are not very useful for this data, because of new line characters embedded in records.</p>\n<p>So, one should use a library for parsing CSV which will take care of quoting, embedded new line characters, etc. I have attached a simple replacement of the Unix head command written in Python which will correctly copy n records from the competition's CSV files.</p>\n<p><code>$ python head.py Train.csv 2<br></code><code>&quot;Id&quot;,&quot;Title&quot;,&quot;Body&quot;,&quot;Tags&quot;<br>&quot;1&quot;,&quot;How to check if an uploaded file is an image without mime type?&quot;,&quot;&lt;p&gt;I'd like to check if an uploaded file is an image file (e.g png, jpg, jpeg, gif, bmp) or another file. The problem is that I'm using Uploadify to upload the files, which changes the mime type and gives a 'text/octal' or something as the mime type, no matter which file type you upload.&lt;/p&gt;</code><code>&lt;p&gt;Is there a way to check if the uploaded file is an image apart from checking the file extension using PHP?&lt;/p&gt;<br>&quot;,&quot;php image-processing file-upload upload mime-types&quot;<br></code><code>&nbsp;<br></code></p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "29857",
      "postDate": "08/31/2013 18:06:01",
      "content": "<p>I noticed that at the end of each record there is a \\r character, so what I did was just replace all the \\n with spaces and the replaced all the \\r with \\n. Let me know if there's something wrong with this approach.</p>\n<p><code>#!/bin/bash</code></p>\n<p><code>if [ -z &quot;$1&quot; ] ; then<br> echo &quot;First replaces all the \\\\n with spaces then replaces all the \\\\r with \\\\n&quot;<br> echo &quot;usage: $0 input.csv output.csv&quot;<br> exit 1;<br>fi</code></p>\n<p><code>tr '\\n' ' ' &lt; &quot;$1&quot; | tr '\\r' '\\n' &gt; &quot;$2&quot;<br></code></p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "29865",
      "postDate": "08/31/2013 21:18:53",
      "content": "<p>Thanks Dmitrim, that's very useful!</p>",
      "rawMarkdown": "",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 29812,
      "author_name": "wcukierski",
      "author_url": "",
      "post_date": "08/30/2013 22:27:27",
      "content": "<p>The sample count should align with the Ids (starts at 1 in the train set and ends with&nbsp;8047532 in the test set).</p>\n<p>This is a <strong><em>beast</em></strong> of a csv file, so we expect there to be a teething period and possibly some nasty edge cases. &nbsp;Bear with us if the dataset has &nbsp;bugs within.</p>\n<p>Mac users - you may have to use a program like Keka if the default unzipping &nbsp;does not spit out a csv file for Train.zip.</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 29813,
      "author_name": "",
      "author_url": "",
      "post_date": "08/30/2013 22:42:53",
      "content": "<p>There's a few really nasty cases involving MATLAB data and code, it's mostly just nested \\n and &quot; that throw things for a loop. Maybe URL encoding them, or using a uniquely guaranteed separator instead of &quot;field&quot;,&quot;field&quot;? I.e. remove all ~ from content, then use ~ as separators.<br><br>It might also be worthwhile to include a sample_train.csv and sample_test.csv, so participants can preview the data without potentially locking up slower (or virtual) machines.</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 29814,
      "author_name": "tafkas",
      "author_url": "",
      "post_date": "08/30/2013 22:44:44",
      "content": "<p>[quote=William Cukierski;29812]Mac users - you may have to use a program like Keka if the default unzipping &nbsp;does not spit out a csv file for Train.zip.[/quote]</p>\n<p>Archiver.app seems to work. Produces:</p>\n<p>MD5 (Train.csv) = 880a8869d61bcce1f26072d9f4797cb9</p>\n<p>MD5 (Test.csv) = cac7cb73cf4061d8f74f9b5a094e66ab</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 29815,
      "author_name": "rohits",
      "author_url": "",
      "post_date": "08/30/2013 22:47:19",
      "content": "<p>Adrian:</p>\n<p>I'm sure you know this, but just for the record a simple one-liner like</p>\n<p><code>head -n [number of lines] Train.csv &gt; sample_train.csv</code></p>\n<p>should do just that.</p>\n<p>&nbsp;</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 29817,
      "author_name": "piotrkuchta",
      "author_url": "",
      "post_date": "08/30/2013 23:18:02",
      "content": "<p>Archiver didn't quite work for me, for a reason, the following did:</p>\n<p>&nbsp;</p>\n<p><code>&nbsp;$ sudo port install p7zip<br></code><code>&nbsp;$ 7za x Train.zip<br></code></p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 29840,
      "author_name": "",
      "author_url": "",
      "post_date": "08/31/2013 11:36:03",
      "content": "<p>[quote=Rohit Sivaprasad;29815]</p>\n<p><code>head -n [number of lines] Train.csv &gt; sample_train.csv</code></p>\n<p>[/quote]</p>\n<p>Had no idea you could do this, thanks!</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 29853,
      "author_name": "piotrkuchta",
      "author_url": "",
      "post_date": "08/31/2013 15:31:44",
      "content": "<p>Unfortunately, traditional line based Unix tools for working with text files like head, tail, wc, etc., are not very useful for this data, because of new line characters embedded in records.</p>\n<p>So, one should use a library for parsing CSV which will take care of quoting, embedded new line characters, etc. I have attached a simple replacement of the Unix head command written in Python which will correctly copy n records from the competition's CSV files.</p>\n<p><code>$ python head.py Train.csv 2<br></code><code>&quot;Id&quot;,&quot;Title&quot;,&quot;Body&quot;,&quot;Tags&quot;<br>&quot;1&quot;,&quot;How to check if an uploaded file is an image without mime type?&quot;,&quot;&lt;p&gt;I'd like to check if an uploaded file is an image file (e.g png, jpg, jpeg, gif, bmp) or another file. The problem is that I'm using Uploadify to upload the files, which changes the mime type and gives a 'text/octal' or something as the mime type, no matter which file type you upload.&lt;/p&gt;</code><code>&lt;p&gt;Is there a way to check if the uploaded file is an image apart from checking the file extension using PHP?&lt;/p&gt;<br>&quot;,&quot;php image-processing file-upload upload mime-types&quot;<br></code><code>&nbsp;<br></code></p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 29857,
      "author_name": "dmitrim",
      "author_url": "",
      "post_date": "08/31/2013 18:06:01",
      "content": "<p>I noticed that at the end of each record there is a \\r character, so what I did was just replace all the \\n with spaces and the replaced all the \\r with \\n. Let me know if there's something wrong with this approach.</p>\n<p><code>#!/bin/bash</code></p>\n<p><code>if [ -z &quot;$1&quot; ] ; then<br> echo &quot;First replaces all the \\\\n with spaces then replaces all the \\\\r with \\\\n&quot;<br> echo &quot;usage: $0 input.csv output.csv&quot;<br> exit 1;<br>fi</code></p>\n<p><code>tr '\\n' ' ' &lt; &quot;$1&quot; | tr '\\r' '\\n' &gt; &quot;$2&quot;<br></code></p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 29865,
      "author_name": "piotrkuchta",
      "author_url": "",
      "post_date": "08/31/2013 21:18:53",
      "content": "<p>Thanks Dmitrim, that's very useful!</p>",
      "votes": null,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "29809": "",
    "29812": "",
    "29813": "",
    "29814": "",
    "29815": "",
    "29817": "",
    "29840": "",
    "29853": "",
    "29857": "",
    "29865": ""
  },
  "source": "meta"
}