Issue
have a python dataframe.
df1
Load Instance_name counter_name counter_value
0 A bytes_read 0
0 A bytes_written 90
0 B bytes_read 100
0 B bytes_Written 90
1 A bytes_read 10
1 A bytes_written 940
1 B bytes_read 1100
1 B bytes_written 910
To simplify view, I need something like below ex. transform counter_name column fields to columns and rearrange data.***
df2 =
Load Instance_name bytes_read bytes_written
0 A 0 90
0 B 100 90
1 A 10 940
1 B 1100 910
I am new to python dataframe libraries and not sure the right way to achieve this.
Solution
Try this:
df.set_index(['Load', 'Instance_name', 'counter_name'])['counter_value'].unstack()
Output:
counter_name Load Instance_name bytes_Written bytes_read bytes_written
0 0 A NaN 0.0 90.0
1 0 B 90.0 100.0 NaN
2 1 A NaN 10.0 940.0
3 1 B NaN 1100.0 910.0
Note typo in input dataframe bytes_Written and bytes_written.
Answered By - Scott Boston
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.