I am studying for Python 2.7.6 with pycharm.
This time, I read the csv file written in Japanese to be analyzed A garbled file was output. As a result of various investigations, it was solved by the following method.
Garbled files can be created in the same way as the previously created Entry. I did it.
import pandas as pd
import os
#Specify the path to the working directory where the data is stored
os.chdir("/File path to directory")
#read csv
df= pd.read_csv("japanese.csv")
print df
However, when reading csv, the character code was not specified, so The garbled file was successfully read.
So, when I read the csv file with SHIFT-JIS by the following method, The csv file was displayed in Japanese!
import pandas as pd
import os
#Specify the path to the working directory where the data is stored
os.chdir("/File path to directory")
#Reading csv with specified character code
df= pd.read_csv("japanese.csv",encoding="SHIFT-JIS")
print df
Now that the Japanese csv file has been read in this way, it's time to process the data! However, while playing with the character code, I changed the column specified in Japanese. I couldn't get it and struggled again ...
Explicitly specify column to fetch only the columns you want loc [:, "desired column name"] If you write, it will get all the columns under "desired column name". Here has a detailed explanation. As a result, if you write as follows, The column where "the name of the column you want" is written I was able to get it gently!
import pandas as pd
import os
#Specify the path to the working directory where the data is stored
os.chdir("/File path to directory")
#Reading csv with specified character code
df= pd.read_csv("japanese.csv,encoding="SHIFT-JIS"")
column = df.loc[:,[u'The name of the column you want']]
print column
I've stumbled on the basics this time as well, If anyone has the same problem, it would be helpful ...
Recommended Posts