python - Pandas: Fill in missing indexes with specific ordered values that are already in column. -
i have extracted one-column dataframe specific values. dataframe looks like:
commodity 0 cocoa 4 coffee 6 maize 7 rice 10 sugar 12 wheat
now want respectively fill each index has no value value above in column should this:
commodity 0 cocoa 1 cocoa 2 cocoa 3 cocoa 4 coffee 5 coffee 6 maize 7 rice 8 rice 9 rice 10 sugar 11 sugar 12 wheat
i don't seem pandas documentation working text data. help!
i create new index pd.rangeindex
. works range
need pass number 1 greater max number in current index.
df.reindex(pd.rangeindex(df.index.max() + 1)).ffill() commodity 0 cocoa 1 cocoa 2 cocoa 3 cocoa 4 coffee 5 coffee 6 maize 7 rice 8 rice 9 rice 10 sugar 11 sugar 12 wheat
Comments
Post a Comment