Skip to content
Advertisement

TypeError: Expected binary or unicode string, got 618.0


I’ve been trying to implement this ML Linear Model into my dataset. (https://www.tensorflow.org/tutorials/estimator/linear)
Language: Python 3.8.3
Lİbraries: TensorFlow 2.4.0
Numpy: 1.19.3
Pandas
Matplotlib
and the others:
JavaScript
JavaScript

ss1517 is the name of my dataset. It is a CSV file with 4116 rows and 20 columns and has lots of NaN values( There is no column that hasn’t NaN value)

JavaScript

CATEGORICAL_COLUMNS are the categorical columns in my dataset.
NUMERIC_COLUMNS are the numeric columns in my dataset.

JavaScript
JavaScript
JavaScript

I have this error(TypeError: Expected binary or unicode string, got 618.0) every time I tried to fill the NaN values with df.fillna(method="ffill") , df.fillna(method="bfill") , df.fillna(value = 0), ordf.fillna(value="randomstringvalues). I also tried to drop the NaN values with df.dropna()
Needless to say, when I tried to run my code with NaN values it couldn’t work.
I have two questions.
The first one, how could I handle my NaN values so that I won’t see this error (TypeError: Expected binary or unicode string, got 618.0) in the future?
The second one, how can I get rid of this error and implement my dataset into this model swiftly?
P.S.: I am positive that I did not make any typos.

Advertisement

Answer

MY guess is that you have some non-unicode characters in your data. Non unicode characters are like this: � ä

anything that is not a letter, number or symbol. you have two options here, to find all these characters and replace them with something else or remove them.

Or you can use a proper encoding when reading the csv file. pandas.read_csv

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement