Issue
I have pandas dataframe like this:
api_url
"url": "https://apis.asia.pntk.cloud/asiaerState",
"url": "https://apis.asia.pntk.cloud/M6518&=38396885",
"url": "https://apis.asia.pntk.cloud/=38396885"
"url": "https://apis.asia.pntk.cloud/518112A",
In the values there could be ',' at the end. I want to trip all special character, take only the actual api url, so the output dataframe would like this:
api_url
https://apis.asia.pntk.cloud/asiaerState
https://apis.asia.pntk.cloud/M65181150%-48UXM%2CNA&so85
https://apis.asia.pntk.cloud/96885
https://apis.asia.pntk.cloud/5181150%2CC9300-48UXM%2A
How can I achieve this?
Solution
Hi, You can try this one. it will solve your Issue.
d = {'api_url': ['"url": "https://apis.asia.pntk.cloud/asiaerState"',
'"url": "https://apis.asia.pntk.cloud/M65181150%-48UXM%2CNA&solutionId=38396885",',
'"url": "https://apis.asia.pntk.cloud/CNA&solutionId=38396885"',
'"url": "https://apis.asia.pntk.cloud/5181150%2CC9300-48UXM%2CNA"']}
df = pd.DataFrame(data=d)
Input:
api_url
0 "url": "https://apis.asia.pntk.cloud/asiaerState"
1 "url": "https://apis.asia.pntk.cloud/M65181150...
2 "url": "https://apis.asia.pntk.cloud/CNA&solut...
3 "url": "https://apis.asia.pntk.cloud/5181150%2...
Solution:
df['api_url'] = df['api_url'].str.replace('"',"").replace(',',"").str.lstrip("url: ")
Output:
api_url
0 https://apis.asia.pntk.cloud/asiaerState
1 https://apis.asia.pntk.cloud/M65181150%-48UXM%...
2 https://apis.asia.pntk.cloud/CNA&solutionId=38...
3 https://apis.asia.pntk.cloud/5181150%2CC9300-4...
Answered By - sayantan ghosh
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.