LoginSignup
3
4

More than 5 years have passed since last update.

DataFrameを整形して表示する

Posted at

DataFrameのデータを整形したい

Pandasを使っているとDataFrameのデータをそのままmarkdownに貼りたいとか、slackに貼りたいって時がって、その時に使います。


import pandas as pd
from tabulate import tabulate


df=pd.DataFrame.from_dict({
    'A': [1,2,3],
    'B': [4,5,6],
    'C': [7,8,9],
    })

print(tabulate(df, df.columns,tablefmt='github', showindex=False))

#出力結果
|   A |   B |   C |
|-----|-----|-----|
|   1 |   4 |   7 |
|   2 |   5 |   8 |
|   3 |   6 |   9 |

これでデータをメール、チャットに貼り付けたりしてる。

3
4
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
4