Pandas DataFrame data structures and database 03_Series _ reindexing

# Here to learn index
import pandas as pd

# Let's rebuild Series and DataFrame index entry

#Series type index rebuild is the index reordering REINDEX, no value is NaN3
# objs1 pd.Series = ([1,2,5,3,7,4,5], index = [l, 2,3 , 4,5,6,7])
# Print (objs1)
# objs2 objs1.reindex = ([ "A", "B", "C", "D", "E", "F", "G" ], fill_value = "0") # do not change the original data, the default value fill_value
# Print (objs2)

#DataFrame索引reindex
data={
"name":["唐浩","小王","老王","赵三","李四"],
"sex":["男","女","男","女","男"],
"year":[37,22,15,18,33],
"city":["成都","北京","上海","成都","深圳"]
}
df1=pd.DataFrame(data,index=["a","b","c","d","e"],columns=["name","year","sex","city"])
print(df1)
df2=df1.reindex(["a","c","d","e","b","f"],fill_value="00") #不改变原数据
print(df2)

Guess you like

Origin www.cnblogs.com/yiyea/p/11441793.html