I am facing difficulty with the correct syntax of the if condition. I want to apply the condition to check the equality of a string. But the way i am trying to do it, is giving me an error:
AttributeError: 'str' object has no attribute 'any'
for :
for a in prod_comm:
if prod_comm['label']==('label":"neg"}').any():
prod_pos.append(a)
or :
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
for :
for a in prod_comm:
if prod_comm.label==('label":"neg"}'):
prod_neg.append(a)
What I am trying to do is: have a dataframe with 2 columns- c and label. I want to divide this dataframe into different files based on the type of label, which is either:
label":"neg"} or label":"pos"}
How may i go forward with the classification? I guess there is an issue with the syntax i am using, but can't find the correct syntax on the net.
Example dataset:
comment label
0 need 3 bhk house "label": "neg"}
2 tried to list my property "label": "neg"}
22 i have issue with the map "label": "neg"}
24 also help with the rental agreements "label": "pos"}
37 sort option should be available. "label": "pos"}
expected output:
two datasets:
prod_pos - with the comments corresponding to label: "label": "pos"}
prod_neg - with the comments corresponding to label: "label": "neg"}
i.e.
prod_pos:
comment label
24 also help with the rental agreements "label": "pos"}
37 sort option should be available. "label": "pos"}
prod_neg:
comment label
0 need 3 bhk house "label": "neg"}
2 tried to list my property "label": "neg"}
22 i have issue with the map "label": "neg"}
Thanks for your help!
Aucun commentaire:
Enregistrer un commentaire