LoginSignup
3
3

More than 3 years have passed since last update.

pandasで2行目をカラム名にしたい

Posted at

pandasでのデータ読み込み時に困った

Excelシートを読み込む際に、1行目に邪魔な文字が入っていたので、カラム名が「Unnamed...」ばかりになった。

二行目からデータとして取得するためには、
1. 最初にデータを読み込み
2. データのカラム名を変更
といった処理が必要になりそうで、ダルイ。。

と思っていた矢先、先人のQiitaの記事を発見。
以下はその記事からの抜粋。


課題

image.png

解決策

pandasのskiprowsを使用して最初のいらない箇所をスキップしてExcelファイルを読み込む。


df = pd.read_excel(excel_file_path, skiprows=2, header=[0, 1])
3
3
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
3
3