HI, I am fairly new to Anvil. I am trying to get a simple mockup where in I pass a string to my colab notebook and I get a result back. I am getting a problem saying that there is an AttributeError: ‘DataFrame’ object has no attribute ‘post_likes_count’. I have attached my code. Can you please help.
@anvil.server.callable
def predict_iris(instusername):
df= pd.read_excel('/content/SampleData_sample.xlsx')
influsername = instusername
df1=df[df.influencer_username == influsername]
df1['response']= 'Null'
for index, row in df1.iterrows():
hashtag_list = []
regex = "#(\w+)"
hashtag_list = re.findall(regex,df1.post_text[index])
df1.response[index]= hashtag_list
avg_likes= df1.post_likes_count.mean()
df2= df1.explode('response')
df2['tag']= 1
tabl1 = pd.pivot_table(df2, values=['tag', 'post_likes_count'], index=['response'], aggfunc={'post_likes_count': np.mean, 'tag': np.sum})
df2_anl= tabl1.reset_index()
df2_anl['response1'] = df2_anl.response.str.lower()
## error is coming up on the line below
df2_anl.score = ((df2_anl.post_likes_count)/(avg_likes))*df2_anl.tag
df2_anl['score'] = df2_anl.tag
df2_inter= df2_anl.sort_values(by=['score'], ascending = False).head()
df3 = pd.DataFrame(columns = ['hash1', 'hash2', 'hash3', 'hash4', 'hash5'])
if(df2_inter.shape[0]>4):
df3= df3.append({'hash1' : df2_inter['response'].iloc[0], 'hash2' : df2_inter['response'].iloc[1], 'hash3' : df2_inter['response'].iloc[2], 'hash4' : df2_inter['response'].iloc[3], 'hash5' : df2_inter['response'].iloc[4]}, ignore_index = True)
elif(df2_inter.shape[0]==4):
df3= df3.append({'hash1' : df2_inter['response'].iloc[0], 'hash2' : df2_inter['response'].iloc[1], 'hash3' : df2_inter['response'].iloc[2], 'hash4' : df2_inter['response'].iloc[3]}, ignore_index = True)
elif(df2_inter.shape[0]==3):
df3= df3.append({'hash1' : df2_inter['response'].iloc[0], 'hash2' : df2_inter['response'].iloc[1], 'hash3' : df2_inter['response'].iloc[2]}, ignore_index = True)
elif(df2_inter.shape[0]==2):
df3= df3.append({'hash1' : df2_inter['response'].iloc[0], 'hash2' : df2_inter['response'].iloc[1]}, ignore_index = True)
elif(df2_inter.shape[0]==1):
df3= df3_br.append({'hash1' : df2_inter['response'].iloc[0]}, ignore_index = True)
else:
df3
sty = df3.hash1[0] + " " + df3.hash2[0] + " " + df3.hash3[0] + " " + df3.hash4[0] + " " + df3.hash5[0]
return sty