Reputation: 6141
I have one dateframe:
idx_value val1 val2
idx 1 5
idx 2 6
idx 3 7
idx 4 8
I wonder if it is possible to convert table in html as following:
val1 val2
1 5
idx 2 6
3 7
4 8
I only want to show idx once. Thank you
Upvotes: 0
Views: 39
Reputation: 402922
Try something like a groupby
+ replace
+ set_value
:
df['idx_value'] = df.groupby('idx_value')['idx_value']\
.apply(lambda x: x.str.replace('.*', '').set_value(len(x) // 2 - 1, x[0]))
df
idx_value val1 val2
0 1 5
1 idx 2 6
2 3 7
3 4 8
Upvotes: 1