0

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

kpdawson24
  • 23
  • 4
  • 1
    Usually, after `pd.crosstab`, one only needs to add `.reset_index()` for getting what you want. – PaulS Nov 19 '22 at 10:20
  • thank you! i left off my parantheses which, for reasons i'll hopefully come to understand, did not throw an error but also did not accomplish the desired effect. – kpdawson24 Nov 19 '22 at 15:06

1 Answers1

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