I’m new in pandas and trying to do some converting on the dateframe but I reach closed path.
my data-frame is:
JavaScript
x
7
1
entity_name request_status dcount
2
0 entity1 0 1
3
1 entity1 1 6
4
2 entity1 2 13
5
3 entity2 1 4
6
4 entity2 2 7
7
I need this dataframe to be like the following:
JavaScript
1
4
1
index 0 1 2
2
entity1 1 6 13
3
entity2 0 4 7
4
as it shown I take the entity_name column as index without duplicates and the columns names from request_status column and the value from dcount
so please any one can help me to do that ?
many thanks
Advertisement
Answer
you can use pivot_table:
JavaScript
1
3
1
a = pd.pivot_table(df, values = 'dcount', index='entity_name', columns='request_status').fillna(0)
2
a = a.astype(int)
3