I cant change the 0 (see the image) in the columns or even add column name
similar = pd.DataFrame()
for question, rating in ratings:
similar=similar.append(get_similar(question, rating), ignore_index=True)
similar.head(10)
similar.sum().sort_values(ascending=False).head(17)
I've tried renaming and everything but I cant change this, when I tried
similar=pd.DataFrame(columns=['new_text','new_text1'])
it just added inside the courses.
CodePudding user response:
The line similar=pd.DataFrame(columns=['new_text','new_text1'])
will return a new dataframe with only column names but no rows.
There are two issues:
- You have not specified the dataframe whose column name you want to assign or change.
- Wrong syntax of changing or assigning column name
The correct way to assign column names:
df.columns = ['col1','col2']
To replace the names:
similar.rename(columns= {'col1':'new_col1','col2':'new_col2'}, inplace = True)