LoginSignup
2
2

More than 5 years have passed since last update.

pandas.DataFrame備忘録

Last updated at Posted at 2018-04-12

DataFrameまとめ

作成

qiita.py
import pandas as pd

# csv 読み込み
df = read_csv(
    import_filename,
    comment = '#' # '#'以降はcommentとしてエスケープする
    index_col = 0 # column '0' をindex columnとして設定(keyを設定すればそのcolumnがindexになる)
    )

df.to_csv(
    export_filename,
    index = None # Noneとすると頭のindexなしで出力(デフォルトではindexごと出る)
    )

追加

qiita1.py
new_column = np.arange(10) # tuple, list, np.ndarrayなどが可能
df["new_column_name"] = new_column

Sort

df.sort_values,df.sort_indexで値、インデックスをもとにソートできる。

Tips

  • df["col"] = df["col"].astype(int) でint型に変換できる。
  • DFの統計量を簡単に知るには、df.describe()がべんり。
2
2
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
2
2