LoginSignup
2
4

More than 5 years have passed since last update.

pandas indexとreindex

Posted at
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

indexはindex振りなおすけど、値は追随。

reindexはindex振りなおすけど、値は追随しないので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
2
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
2
4