【Python】Pandas ~ 入門編 ~

■ はじめに

https://dk521123.hatenablog.com/entry/2018/03/28/224532

の続き。

データ解析支援ライブラリ Pandas について、ちょっとづつまとめる

目次

【1】Pandas (パンダス)
【2】インストール
【3】用語整理
 1)Series(シリーズ)
 2)DataFrame(データフレーム)
【4】サンプル
【5】トラブル

【1】Pandas (パンダス)

Pythonでデータ解析を行うためのライブラリ
 ⇒ 表や時系列データを操作するための
   データ構造を作ったり、演算を行うことができる

【2】インストール

pip install pandas

【3】用語整理

1)Series(シリーズ)

1次元のデータを作る

2)DataFrame(データフレーム)

2次元のデータを作る

【4】サンプル

import pandas as pd

df = pd.DataFrame(
  [[0, 2, 4], [1, 3, 5]],
  index=['row1', 'row2'],
  columns=['col1', 'col2', 'col3'])

# https://note.nkmk.me/python-pandas-assign-append/
# 末尾項目追加
df = df.assign(new_col1=False)
# 任意の場所に項目追加
df.insert(len(df.columns) - 1, 'new_col2', True)

print(df)

出力結果

      col1  col2  col3  new_col2  new_col1
row1     0     2     4      True     False
row2     1     3     5      True     False

【5】トラブル

* 以下の関連記事にまとめた。

https://dk521123.hatenablog.com/entry/2021/03/19/000000

参考文献

https://qiita.com/koara-local/items/0e56bc1e58b11e4d7a32
https://code-graffiti.com/practice-pandas-in-python/

関連記事

Pandas ~ 基本編 ~
https://dk521123.hatenablog.com/entry/2020/10/14/000000
Pandas ~ 基本編 / データフレーム ~
https://dk521123.hatenablog.com/entry/2021/07/25/000000
Pandas ~ データフレームの相互変換 ~
https://dk521123.hatenablog.com/entry/2022/02/15/000000
Pandas ~ 基本編 / CSV編 ~
https://dk521123.hatenablog.com/entry/2020/11/17/000000
Pandas ~ 基本編 / JSON編 ~
https://dk521123.hatenablog.com/entry/2022/02/16/000000
Pandas ~ 基本編 / Excel編 ~
https://dk521123.hatenablog.com/entry/2020/11/18/000000
Pandas ~ 基本編 / Excel => CSVに変換 ~
https://dk521123.hatenablog.com/entry/2021/01/25/000000
Pandas ~ 基本編 / データのクレンジング ~
https://dk521123.hatenablog.com/entry/2020/04/06/235555
Pandas ~ データ集計編 ~
https://dk521123.hatenablog.com/entry/2021/04/07/105858
Pandas ~ データ連結 / 結合編 ~
https://dk521123.hatenablog.com/entry/2021/07/26/000000
Pandas ~ apply / transform ~
https://dk521123.hatenablog.com/entry/2021/07/27/000000
Pandas ~ to_xxxx / 出力編 ~
https://dk521123.hatenablog.com/entry/2021/04/10/192752
Pandas ~ NaNをNoneに変換する ~
https://dk521123.hatenablog.com/entry/2022/02/20/000000
Pandas の環境設定でのトラブル
https://dk521123.hatenablog.com/entry/2021/03/19/000000
Pandas で Excel を扱った際のトラブル
https://dk521123.hatenablog.com/entry/2021/07/03/000000
NumPy ~ 入門編 ~
https://dk521123.hatenablog.com/entry/2018/03/28/224532
PythonExcel を扱うには
https://dk521123.hatenablog.com/entry/2019/11/05/221010
Python ~ 基本編 / CSV
https://dk521123.hatenablog.com/entry/2019/11/07/214108
Python で Parquet を扱う
https://dk521123.hatenablog.com/entry/2021/11/13/095519