I'm working on a pandas dataframe that contains 3 columns named : drugName, review and rating. I'm trying to get the review according to its rate, if it is higher or equal to 6, so it is a positive review that I must write it in a csv file. Here is my code :
import csv
import pandas as pd
filename ="C:\\Users\Amin Chaari\Desktop\Book1.csv"
def user_text(filename):
with open (filename, encoding="utf8") as f:
datas = csv.reader(f, delimiter = ';')
lines = [row for row in datas]
user={}
try:
for i in range(1,5):
if lines[0][i] != 'condition':
print(lines[0][i])
grouped_column = []
for j,row in enumerate(lines):
if j>0:
grouped_column.append(row[i])
user.update({lines[0][i]:grouped_column})
except IndexError:
pass
df1=pd.DataFrame(user)
df1.groupby(['review'])
return df1
df=user_text(filename)
for i in range (0,40303):
df['rating'][i]=float(df['rating'][i])
for i in range(0,40303):
if df['rating'][i] >= 6:
df['review'].to_csv("C:\\Users\\rev_pos.csv",encoding='utf8')
this the error that I get :
AttributeError: 'str' object has no attribute 'to_csv'