1
2

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.

Pythonのpandasで複数csvファイルを読み込みunionする

Last updated at Posted at 2021-09-19

スクレイピングで出力した、複数csvファイルをunionして、pandasのデータフレームにして分析に用いたときのpythonコードメモ。

import pandas as pd
import glob

csv_files = glob.glob('data/*.csv')

data_list = []

for file in csv_files:
    df = pd.read_csv(file)
    # 列名の.を_に変更
    df = df.rename(columns=lambda x: x.replace('.', '_'))
    data_list.append(df)

df = pd.concat(data_list, axis=0, sort=True)
1
2
1

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?