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

Pandas備忘録

概要

Pandasで個人的に覚えておきたいこと一覧
随時更新します

課題一覧

1・2用のサンプルcsv

Japan America
month start end worktime memo month start end worktime memo
20200408 900 1730 8.5 hello 20200408 900 1730 8.5 hello

1. カラムが複数行存在する際に、2行目をカラム名とする方法

2. 複数行のカラムの読み込み

方法

1・2用のサンプルcsv

Japan America
month start end worktime memo month start end worktime memo
20200408 900 1730 8.5 hello 20200408 900 1730 8.5 hello

1. カラムが複数行存在する際に、2行目をカラム名とする方法

df.columns=df.loc[0,:]
df.drop(0,axis=0)

②(推奨)

df = pd.read_csv("./excel-sample1.csv", skiprows=1)

2. 複数行のカラムの読み込み

df = pd.read_csv("./excel-sample1.csv", header=[0,1])

コラム

  • 複数行カラムの扱い方
print(df.loc[:,'Unnamed: 1_level_0'])
df.loc[:,('Unnamed: 1_level_0','start')]
# ずれるとダメ
df.loc[:,('Unnamed: 1_level_0','end')]
PipoPi
Why not register and get more from Qiita?
  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
No 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
ユーザーは見つかりませんでした