简体   繁体   English

熊猫:重塑数据框

[英]Pandas : reshaping dataframe

I have a dataframe which is currently looks like this,我有一个当前看起来像这样的数据框,

dataframe 1数据框 1

I need to create a dataframe that looks like this.我需要创建一个看起来像这样的数据框。

dataframe 2数据框 2

I need to populate the columns of dataframe 2 from the values from dataframe 1 columns.我需要从数据帧 1 列的值填充数据帧 2 的列。 Image shows the example.图像显示了示例。 What should be the algorithm and process for this?这应该是什么算法和过程?

Here is the sample dataset这是示例数据集

 df_dict = {'hostname': {0: 'Comp890263', 1: 'Comp813682', 2: 'Comp213302', 3: 'Comp839013', 4: 'Comp966241'}, 'days': {0: 90, 1: 90, 2: 90, 3: 90, 4: 90}, 'status': {0: '1', 1: '1', 2: '1', 3: '1', 4: '1'}, 'features': {0: '0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0', 1: '0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0', 2: '0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0', 3: '0,0,0,0,0,0,0,21,0,25,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,21,0,0,0,0,0,0,0,0,0,6,46,0,0,0,0,759,0,0,0,0', 4: '0,0,0,0,0,0,0,43,0,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,43,0,0,0,0,0,0,0,0,0,30,46,0,0,0,0,795,0,0,0,0'}}

There is a similar question here : Pandas column values to columns?这里有一个类似的问题: Pandas column values to columns? . . See if their solutions with .pivot_table or unstack work for you.看看他们的解决方案.pivot_tableunstack了你的工作。

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

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