0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

pandas 読み込み/書き込み

Last updated at Posted at 2022-12-06

csv ファイルの処理

AWS S3のファイルを読み込んでCP932でファイルに書く

AWSのファイルはUTF-8なので読み込み指定し、書き込み時はcp932にして書く。

            dfData = pd.read_csv(url, encoding="utf-8")
            dfData.to_csv(filename, encoding="cp932")

巨大なファイルを読み込んでcp932でファイルに書く

巨大なファイルはメモリも気になるので、分割して読んで追記する。
確認はしていない。

dfData = pd.read_csv(url, encoding="utf-8", chunksize=1000)
isTop = true
for value in dfData:
    if (isTop):
        dfData.to_csv(filename, encoding="cp932", header = False, index = False)
        isTop = false
    else :
        dfData.to_csv(filename, encoding="cp932", mode="a", header = False, index = False)
                    
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?