LoginSignup
0
0

More than 1 year has passed since last update.

[Python]複雑な大量のファイルを処理したい

Last updated at Posted at 2022-03-31

やりたいこと

  • Python でこんなファイルを処理したい
  • 同じようなファイルがめちゃある

サンプルファイル

  • ひとつのセルに、長々しいデータが入っている。
    image.png

Step

# パスを変数に入れる
path = "abc/def"
file_list = glob.glob(path + "/test.csv)

# 空のデータフレームを作成
df_cp_memory = pd.DataFrame()
for file in file_list:
# スラッシュで区切る
    df2 = pd.read_csv(file, header=None , sep='/' )
  # 空のデータフレームに、フ変数にいれたファイルを入れていく
  # 一つ大きなテーブルができる
    df_cp_memory = pd.concat([df_cp_memory, df2])

# 確認
print(df_cp_memory)

# Excelに書き出す
df_cp_memory.to_excel(path + '/cp_memory.xlsx', index=True , header=True )

そのほか

skiprows=1 を設定すると、最初の一行目スキップされる

df2 = pd.read_csv(file, header=None , sep='/' , skiprows=1)
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