pandas index and reindex

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

pandas index and reindex
Load csv with pandas and play with Index
jupyter and pandas installation
pandas resample and rolling
Pandas averaging and listing
Correspondence between pandas and SQL
Key additions to pandas 1.1.0 and 1.0.0
Index of certain pandas usage
Pandas
Precautions when using codecs and pandas
[Pandas] Find quartiles and detect outliers
Ignore # line and read in pandas
How to get a specific column name and index name in pandas DataFrame
[Python] What is pandas Series and DataFrame?
Import of japandas with pandas 1.0 and above
A little scrutiny of pandas 1.0 and dask
How to reassign index in pandas dataframe
[pandas] .csv file reading and display method
Grouping csv and getting minimum value (pandas)
How to use pandas Timestamp and date_range
Read CSV and analyze with Pandas and Seaborn