Home > other > Be urgent!!!! Pandas DataFrame reindex cannot index of problem again
Be urgent!!!! Pandas DataFrame reindex cannot index of problem again
Time:10-16
Learning pandas DataFrame, appears not to reindex index, in the BBS and baidu search, there is no similar search results, whether you have never met this problem? The sample is as follows: The import numpy as np The import pandas as pd ? The from pandas import DataFrame, Series ? data=https://bbs.csdn.net/topics/np.arange (9). Reshape (3, 3) # df=pd DataFrame (index=[' 0 ', '1'], the columns=[' one ', 'two', 'three']) Df=pd DataFrame (data, the index=[' b ', 'a', 'c'], the columns=[' two ', 'one', 'three']) Print (df) Df. Reindex (index=[' a ', 'b', 'c', 'd'], the columns=[' one ', 'two', 'three', 'four'], fill_value='https://bbs.csdn.net/topics/100') Df Two one three 0 1 2 b A, 3, 4, 5 6 7 8 c Two one three 0 1 2 b A, 3, 4, 5 6 7 8 c
CodePudding user response:
CodePudding user response:
ff=df. Reindex (index=[' a ', 'b', 'c', 'd'], the columns=[' one ', 'two', 'three', 'four'], fill_value='https://bbs.csdn.net/topics/100') Print (df) Print (ff)
Have to assign a value after reindex: df=df reindex (index=[' a ', 'b', 'c', 'd'], the columns=[' one ', 'two', 'three', 'four'], fill_value='https://bbs.csdn.net/topics/100')