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')

CodePudding user response:

CodePudding user response:

CodePudding user response:

Or not, as shown above.

CodePudding user response:

reference 5 floor lbywyj reply:
or not, as shown above.

As I send to you, you have to change is not the same as
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)

CodePudding user response:

Brother, reindex is used according to the parameters to generate a new df, if you want to replace the original df, need to reopen the assignment,
Df=df reindex (index=[' a ', 'b', 'c', 'd'],
The columns=[' one ', 'two', 'three', 'four'],
Fill_value='https://bbs.csdn.net/topics/100')
I hope it can help you ~

CodePudding user response:

Ok, is really stupid reason, thanks a lot,

CodePudding user response:

I have also been troubled for a long time, finally see pandas source code solves the
If you want to be on the premise of not change indexes corresponding to the data reset indexed sequential, need to add the axis reindex function dimension and value assignment
Df. Reindex ([' a ', 'b', 'c'], axis="rows")

Axis='rows' reset row index sorting
Axis='columns' reset the column index sorting

For the first time to answer questions encourage ha ~ ~ if you can solve

CodePudding user response:

Df. Reindex (index=[' a ', 'b', 'c', 'd'], the columns=[' one ', 'two', 'three', 'four'], fill_value='https://bbs.csdn.net/topics/100')
Change
Df=df reindex (index=[' a ', 'b', 'c', 'd'], the columns=[' one ', 'two', 'three', 'four'], fill_value='https://bbs.csdn.net/topics/100')
  • Related