0

Here is my code snippet where I am trying to process a column of a pandas dataframe

def langprob(lid_set):
    print lid_set, type(lid_set)
    return 

df['ls']= df.apply(lambda row: langprob(row['lid']), axis=1)

And I am getting the output as follows:

[(fi, 0.8201195597648621, 90), (fy, 0.627633810043335, 4)], <type 'unicode'>

While I want to process the tuples inside the list one by one by iterating, I am not sure how to proceed from here.

How can I iterate or convert the unicode[(fi, 0.8201195597648621, 90), (fy, 0.627633810043335, 4)] to an iterable? I am sure there is an easy way, but I am missing some basics.

P.S: I have looked at this and this SO answers. They weren't of much help!

kingmakerking
  • 2,017
  • 2
  • 28
  • 44
  • If you're talking about converting string -> object, we have questions for that already. See the bottom of my answer here: https://stackoverflow.com/q/48008191/4909087 – cs95 May 29 '18 at 07:45
  • @coldspeed I have tried that option, and I get `AttributeError: ("'unicode' object has no attribute 'apply'", u'occurred at index 0')` – kingmakerking May 29 '18 at 08:00
  • 1
    I mean `import ast; df['iid'] = df['iid'].apply(ast.literal_eval)` – cs95 May 29 '18 at 08:00
  • @coldspeed I have tried that as well, I get `ValueError: malformed string` – kingmakerking May 29 '18 at 08:04
  • I don't know what to tell you. Your string is malformed, parsing it is non-trivial. – cs95 May 29 '18 at 08:09

0 Answers0