Julia: How do I read the Chinese characters in a CSV file? _julia

Source: Internet
Author: User

Often encounter CSV and other related files, which have Chinese characters, very naturally, we will think of READCSV,READDLM and other built-in functions.
However, these are not processed and will report related character errors.

Today, the main point is to discuss the problem in this respect.

Here is a CSV file, flow.csv. Format is as follows:

One, loading Stringencodings library

Pkg.add ("Stringencodings")

Ii. Conduct of relevant processing

Using Stringencodings;
Path = "C:\\users\\desktop\\flow.csv";
data = open (path, enc "GB18030", "R") do stream
    ReadString (stream);
End

If:

For I in the Data
   print (i) End

Output:

But we know that data is a character vector of characters Fu Yi that needs to be parsed into the corresponding CSV format.

Let's see, specifically how, for convenience, we only look at the first 9 lines:

for (I,d) in enumerate (data)
    if i<10
       println ("I: $i,  data content: $d")
    end

Output:

From the above, you can see that the Chinese characters are read out, but we get a character vector with ",", "\ R" and so on, which is not our ultimate goal.

Third, how to become a CSV format.

See the Ultimate kill device:

Data =open (readcsv, PATH, enc "GB18030"); # array{any,2}

Such data is the kind of readcsv format we need.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.