DataFrame.reset_index()
をお使いください
Python
1import pandas as pd
2import numpy as np
3
4# ダミーデータ生成(MultiIndex)
5idx = pd.MultiIndex.from_arrays([
6 pd.date_range('2017/12/01', freq='D', periods=5),
7 np.arange(1, 6)], names=['Date', 'ID']
8)
9df = pd.DataFrame(np.random.randint(0,10, (5,3)), index=idx, columns=['a','b','c'])
10print(df)
11# a b c
12# Date ID
13# 2017-12-01 1 9 6 2
14# 2017-12-02 2 3 0 4
15# 2017-12-03 3 2 9 2
16# 2017-12-04 4 0 6 1
17# 2017-12-05 5 4 2 8
18
19df = df.reset_index()
20print(df)
21# Date ID a b c
22# 0 2017-12-01 1 9 6 2
23# 1 2017-12-02 2 3 0 4
24# 2 2017-12-03 3 2 9 2
25# 3 2017-12-04 4 0 6 1
26# 4 2017-12-05 5 4 2 8
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/12/19 09:47