{"id":414,"date":"2017-06-12T15:51:55","date_gmt":"2017-06-12T15:51:55","guid":{"rendered":"http:\/\/perfectionatic.org\/?p=414"},"modified":"2017-06-12T15:54:02","modified_gmt":"2017-06-12T15:54:02","slug":"reading-dataframes-with-none-utf8-encoding-in-julia","status":"publish","type":"post","link":"https:\/\/perfectionatic.org\/?p=414","title":{"rendered":"Reading DataFrames with non-UTF8 encoding in Julia"},"content":{"rendered":"<p>Recently I ran into problem where I was trying to read a CSV files from a Scandinavian friend into a <code>DataFrame<\/code>. I was getting errors it could not properly parse the <code>latin1<\/code> encoded names.<\/p>\n<p>I tried running<\/p>\n<pre lang=\"julia\">\nusing DataFrames\ndataT=readtable(\"example.csv\", encoding=:latin1)\n<\/pre>\n<p>but the got this error<\/p>\n<pre lang=\"julia\">\nArgumentError: Argument 'encoding' only supports ':utf8' currently.\n<\/pre>\n<p>The solution make use of (StringEncodings.jl)[https:\/\/github.com\/nalimilan\/StringEncodings.jl] to wrap the file data stream before presenting it to the <code>readtable<\/code> function.<\/p>\n<pre lang=\"julia\">\nf=open(\"example.csv\",\"r\")\ns=StringDecoder(f,\"LATIN1\", \"UTF-8\")\ndataT=readtable(s)\nclose(s)\nclose(f)\n<\/pre>\n<p>The <code>StringDecoder<\/code> generates an <code>IO<\/code> stream that appears to be <code>utf8<\/code> for the <code>readtable<\/code> function.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Recently I ran into problem where I was trying to read a CSV files from a Scandinavian friend into a DataFrame. I was getting errors it could not properly parse the latin1 encoded names. I tried running using DataFrames dataT=readtable(&#8220;example.csv&#8221;, encoding=:latin1) but the got this error ArgumentError: Argument &#8216;encoding&#8217; only supports &#8216;:utf8&#8217; currently. The solution [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[74,73],"tags":[92],"class_list":["post-414","post","type-post","status-publish","format-standard","hentry","category-julia","category-julialang","tag-julia"],"_links":{"self":[{"href":"https:\/\/perfectionatic.org\/index.php?rest_route=\/wp\/v2\/posts\/414","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/perfectionatic.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/perfectionatic.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/perfectionatic.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/perfectionatic.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=414"}],"version-history":[{"count":6,"href":"https:\/\/perfectionatic.org\/index.php?rest_route=\/wp\/v2\/posts\/414\/revisions"}],"predecessor-version":[{"id":420,"href":"https:\/\/perfectionatic.org\/index.php?rest_route=\/wp\/v2\/posts\/414\/revisions\/420"}],"wp:attachment":[{"href":"https:\/\/perfectionatic.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=414"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/perfectionatic.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=414"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/perfectionatic.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=414"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}