0
1

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 3 years have passed since last update.

zipの中のフォルダ名一覧をCSVで取得

Last updated at Posted at 2021-02-26

環境

OS: Windows10
ツール: Google Colaboratory
Python ver: 3.7.10
※Colabのバージョン

特にOSが違う場合はでコード部分の引数は変わると思うので気を付けてください。

コード

コード
import zipfile
import pandas as pd
from google.colab import files
uploaded = files.upload()

file_name = list(uploaded)[0]
ary = []
with zipfile.ZipFile(file_name) as z:
  for info in z.infolist():
    info.filename = info.filename.encode('cp437').decode('cp932')
    ary.append([info])
    

df = pd.DataFrame(ary)

file_name = file_name.replace('zip', 'csv')
df.to_csv(file_name, encoding = 'utf-8-sig')

files.download(file_name)

わざわざDataFrameにする必要はないと思いますが、
慣れている方法で書きました。

0
1
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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?