invalid character identifier when reading csv file in pandas

Asked 2 years ago, Updated 2 years ago, 101 views

I want to load the population data csv file downloaded from resas into pandas, but
The following error message occurred:

df File "<ipython-input-13-5abd 90abec 15>", line 4
    df=pd.read_csv(url, encoding="SHIFT-JIS")
                                               ^
SyntaxError: invalid character identifier

I thought it was an elementary mistake, so I tried typing "", "."

import pandas as pd

url='https://drive.google.com/file/d/e/view?usp=sharing'
df=pd.read_csv(url, encoding="SHIFT-JIS") 

# display df

python pandas csv

2022-09-30 14:58

1 Answers

df=pd.read_csv(url, encoding="SHIFT-JIS") appears to be followed by a full-width blank.
If you copied it from the source, that's probably the reason.Try removing the full-width blank.

The next commented issue is probably related to this article.
What to note when having Pandas read the csv in excel output

This can be found in test2.csv in
"·Hashigodaka "" """
" ·Tachisaki "Saki"
This is due to a mixture of Windows extension strings such as .
To read such characters, the character code must be cp932.

encoding='cp932'

Try encoding='cp932'.


2022-09-30 14:58

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.