Reputation: 443
I have a dataframe, in one column I want to extract a specific information. Using split it can be done easily but with Pandas I cannot figure out how to do it.
s = pd.Series(['T:15.0(1.71%),B:7.4(0.03%),P:1e-21'])
I want to extract only 1e-21
I tried
s.str.extract()
But I cannot find the regex to match what I want actually.
Or if there is another way to parse column content.
Thanks
Upvotes: 0
Views: 72
Reputation: 13387
Try:
print(s.str.extract(r"P:([^\,]+)"))
This will return whatever you have after literal: P:
which isn't comma (since I understand comma terminates assignment).
Upvotes: 1
Reputation: 17368
s = pd.Series(['T:15.0(1.71%),B:7.4(0.03%),P:1e-21'])
print(s.str.split(":")[0][-1])
Output:
'1e-21'
Upvotes: 1