dataframe_make
import pandas as pd
import numpy as np
df=pd.DataFrame(np.arange(9).reshape(3,3))
df
#[Out]# 0 1 2
#[Out]# 0 0 1 2
#[Out]# 1 3 4 5
#[Out]# 2 6 7 8
The index is reassigned to the index, but the value follows.
reindex reassigns index, but the value does not follow, so NaN
index
df.index=range(100,103)
df
#[Out]# 0 1 2
#[Out]# 100 0 1 2
#[Out]# 101 3 4 5
#[Out]# 102 6 7 8
reindex
df.reindex(range(100,103))
#[Out]# 0 1 2
#[Out]# 100 NaN NaN NaN
#[Out]# 101 NaN NaN NaN
#[Out]# 102 NaN NaN NaN
Recommended Posts