'TypeError: can only concatenate str (not "numpy.float64") to str data set question
Please help Ive spent three hours on stack now i tried ''.join, str, removing the "+" for "," and nothing works to remove this error! The last 2 comments is where the error happens! #Description: Build a anime recommendation using python #Store the data df = pd.read_csv('animes.csv') #Show the first 3 rows of data df.head(2)
#Count of the number of rows/animes in the data set and the number oof colums
df.shape
#List of wanted columns for anime recommendations
columns =['title','synopsis','genre','aired','episodes']
#Data updated
df[columns].head(3)
#Missing values check
df[columns].isnull().values.any()
#Create a funtion to combine the values of the new columns into a single string
def get_new_features(data):
new_features =[]
for i in range (0, data.shape[0]):
new_features.append(data['title'][i]+''+data['synopsis'][i]+''+data['genre'][i]+''+data['aired'][i]+''+data['episodes'][i])
return new_features
#Create a column to hold combine strings
df ['new_features'] = get_new_features(df)
#show data
df.head(4)
--------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-97-d5676456ab85> in <module>()
1 #Create a column to hold combine strings
----> 2 df ['new_features'] = get_new_features(df)
3
4 #show data
5 df.head(4)
<ipython-input-95-842623950c0e> in get_new_features(data)
3 new_features =[]
4 for i in range (0, data.shape[0]):
----> 5 new_features.append(data['title'][i]+''+data['synopsis'][i]+''+data['genre'][i]+''+data['aired'][i]+''+data['episodes'][i])
6
7 return new_features
TypeError: can only concatenate str (not "numpy.float64") to str
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
