简体   繁体   English

尝试从 pandas 交叉表创建填充的 dataframe

[英]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)我有一个 numpy 数组,通常看起来像这样(如果有任何意义,它是从pd 交叉表创建的)

Person 1to1 Person Attribute 1to1人物属性 Circumstance环境 Outcome A Count结果计数 Outcome B Count结果 B 计数
ABC1 ABC1 1 1个 X X 100 100 25 25
DEF2 DEF2 2 2个 X X 1 1个 2 2个
Y 0 0 2 2个
XYZ1 XYZ1 1 1个 X X 33 33 5 5个
Y 5 5个 10 10

that I'd like to turn into a pandas dataframe that looks like我想变成 pandas dataframe 看起来像

Person 1to1 Person Attribute 1to1人物属性 Circumstance环境 Outcome A Count结果计数 Outcome B Count结果 B 计数
ABC1 ABC1 1 1个 X X 100 100 25 25
DEF2 DEF2 2 2个 X X 1 1个 2 2个
DEF2 DEF2 2 2个 Y 0 0 2 2个
XYZ1 XYZ1 1 1个 X X 33 33 5 5个
XYZ1 XYZ1 1 1个 Y 5 5个 10 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.我已经尝试了一些 for 循环来处理任何有空白的情况,并将其替换为之前观察到的值,但我遇到了这样一系列错误,我决定我可能会完全走上错误的道路。

Thank you, everybody谢谢大家

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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