Reputation: 23
I have a lot of key:value
strings in my dataframe. How can I remove just the keys?
Suppose the dataframe looks like this:
0 1 2 3 4 5 6
0 2 1:-0.860107 2:-0.111111 3:-1 4:-1 5:-1 6:-0.777778
1 2 1:-0.859671 2:-0.111111 3:-0.333333 4:-0.333333 5:-0.111111 6:0.333333
2 2 1:-0.857807 2:-0.555556 3:-1 4:-1 5:-1 6:-0.777778
Upvotes: 2
Views: 762
Reputation: 30050
pandas.DataFrame.applymap() is also intuitive.
df = df.applymap(lambda x: str(x).split(':')[-1])
# print(df)
0 1 2 3 4 5 6
0 2 -0.860107 -0.111111 -1 -1 -1 -0.777778
1 2 -0.859671 -0.111111 -0.333333 -0.333333 -0.111111 0.333333
2 2 -0.857807 -0.555556 -1 -1 -1 -0.777778
Upvotes: 1