简体   繁体   中英

Trying to create a filled dataframe from pandas crosstab

I've got a numpy array that looks like this, in general (it was created from a pd crosstable if that's of any significance)

Person 1to1 Person Attribute Circumstance Outcome A Count Outcome B Count
ABC1 1 X 100 25
DEF2 2 X 1 2
Y 0 2
XYZ1 1 X 33 5
Y 5 10

that I'd like to turn into a pandas dataframe that looks like

Person 1to1 Person Attribute Circumstance Outcome A Count Outcome B Count
ABC1 1 X 100 25
DEF2 2 X 1 2
DEF2 2 Y 0 2
XYZ1 1 X 33 5
XYZ1 1 Y 5 10

I've attempted some for loops to take any situation where there's a blank and replace it with the previously observed value, but I've hit such an array of errors I've decided I might be headed down the wrong path entirely.

Thank you, everybody

pd.DataFrame(your ndarray).fillna(method = 'ffill')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM