1

The data variable is a percentage i calculated to rank each input. when i run this code it is returning with this error. "ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all()." Please let me know how to fix this or possible helpers.

Thanks!!

data on twitter stats

def create_column(data):
    if data <= 1.1175:
        grouping = 'not popular'
    elif data > 1.1176 and data < 2.235:
        grouping = 'Mildly not popular'  
    elif data > 2.236 and data < 3.3525:
        grouping = 'Mild Popularity'
    elif data >=4.47:
        grouping = 'popular'
    else:
        grouping = 'Neutral'
    return grouping
data = df1['score']

create_column((data))

1 Answers1

1

If i have the dataframe right from your picture, This should work with your code (if not, can you post it in text for me, i'd like to solve this, pandas is my new addiction):

df = pd.DataFrame({'Retweets': [117489,117429,111489,113489],
                   'Score': [0.081086,0.081036,0.081286,0.021086]})

def create_column(data):
    if data <= 1.1175:
        grouping = 'not popular'
    elif data > 1.1176 and data < 2.235:
        grouping = 'Mildly not popular'  
    elif data > 2.236 and data < 3.3525:
        grouping = 'Mild Popularity'
    elif data >=4.47:
        grouping = 'popular'
    else:
        grouping = 'Neutral'
    return grouping

Popularity={}
for item in df.Score:
    Popularity.update({item:create_column(item)})

df['Popularity']=df['Score'].map(Popularity) 
oppressionslayer
  • 6,942
  • 2
  • 7
  • 24