Issue
I have a large pandas dataframe where one of the columns has weird formatting. I am tring to replace the string, but I keep getting error messages saying: 'error: unterminated character set at position 0'. An example small dataframe is below:
col 1 col 2
Amy [{'?username': 'usr/AMY16548'}]
Jack [{'?username': 'usr/JACK15822'}]
Sarah [{'?username': 'usr/SARAH00001'}]
Desired result
col 1 col 2
Amy usr/AMY16548
Jack usr/JACK15822
Sarah usr/SARAH00001
Solution
Little bit barbaric way, I m sure there is pandas way how to do this, but i dont know it.
y=0
for x in df.iloc[:,1]:
#print (x)
text=str(x)
index = text.find('usr')
df.iloc[y,1]=text[index:-2]
y+=1
print (df)
Answered By - Jakub
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.