Help us understand the problem. What is going on with this article?

Pandas を用いて複数シートからなるエクセルファイルをデータフレームに取り込む

More than 1 year has passed since last update.
以下のような2枚のシートからなるエクセルファイルをデータフレームに取り込む場合
Excelsampledata.xls[sheet1]

sheet1.png

Excelsampledata.xls[sheet2]

sheet2.png

サンプルプログラム
sample.py
import pandas as pd

#エクセルファイルを読み込み
input_file = pd.ExcelFile("Excelsampledata.xls")
#シート名を格納
input_sheet_name=input_file.sheet_names
#シートの枚数を確認
num_sheet=len(input_sheet_name)

#de_listというリストを作成し、エクセルのシートをリストに格納していく。
df_list=[]
for sheet in input_sheet_name:
    df_list.append(input_file.parse(sheet))

#カラムを並び替えないで、読み込んだエクセルのシートを連結し、データフレームに格納する。
df=pd.DataFrame()
for i in range(num_sheet) :
    df=df.append(df_list[i])[df_list[0].columns.tolist()]

#欠損値を削除する。
df=df.dropna()
結果(データフレーム(df))

result.png

Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away