Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/359.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何改变大熊猫的索引和转座_Python_Pandas_Dataframe_Pandas Groupby - Fatal编程技术网

Python 如何改变大熊猫的索引和转座

Python 如何改变大熊猫的索引和转座,python,pandas,dataframe,pandas-groupby,Python,Pandas,Dataframe,Pandas Groupby,我是新来的熊猫,试图在日期框架上做一些转换,但我达到了封闭的路径 我的数据框是: entity_name request_status dcount 0 entity1 0 1 1 entity1 1 6 2 entity1 2 13 3 entity2 1 4 4 entity2 2 7

我是新来的熊猫,试图在日期框架上做一些转换,但我达到了封闭的路径

我的数据框是:

  entity_name  request_status  dcount
0  entity1          0           1
1  entity1          1           6
2  entity1          2          13
3  entity2          1           4
4  entity2          2           7
我需要此数据帧如下所示:

index      0      1      2
entity1    1      6      13
entity2    0      4      7
如图所示,我将entity_name列作为索引,没有重复项,列名称来自request_status列,值来自dcount

所以请有人能帮我吗

非常感谢

您可以使用:

定期工作也包括:

df.pivot(values='dcount', index='entity_name', columns='request_status').fillna(0).astype(int)

难以置信,非常感谢它工作良好,正确。但是我有一个简单的问题,数字是浮点数,我能在新的df中使它们成为整数吗?
df.pivot(values='dcount', index='entity_name', columns='request_status').fillna(0).astype(int)