This is due to the series `df[cat]`

containing elements that have varying data types e.g.(strings and/or floats). This could be due to the way the data is read, i.e. numbers are read as float and text as strings or the datatype was float and changed after the `fillna`

operation.

In other words

pandas data type ‘Object’ indicates mixed types rather than str type

so using the following line:

```
df[cat] = le.fit_transform(df[cat].astype(str))
```

should help

### Related Contents:

- Label encoding across multiple columns in scikit-learn
- pandas dataframe columns scaling with sklearn
- A column-vector y was passed when a 1d array was expected
- ValueError: numpy.ndarray size changed, may indicate binary incompatibility. Expected 88 from C header, got 80 from PyObject
- How to convert a Scikit-learn dataset to a Pandas dataset
- What are the pros and cons between get_dummies (Pandas) and OneHotEncoder (Scikit-learn)?
- Run an OLS regression with Pandas Data Frame
- How to use sklearn fit_transform with pandas and return dataframe instead of numpy array?
- How to one-hot-encode from a pandas column containing a list?
- ValueError: Unknown label type: ‘unknown’
- Impute categorical missing values in scikit-learn
- The easiest way for getting feature names after running SelectKBest in Scikit Learn
- classifiers in scikit-learn that handle nan/null
- Stratified Sampling in Pandas
- TfidfVectorizer in scikit-learn : ValueError: np.nan is an invalid document
- Scikit-learn balanced subsampling
- How to retain column headers of data frame after Pre-processing in scikit-learn
- transform scipy sparse csr to pandas?
- Scikit-Learn’s Pipeline: A sparse matrix was passed, but dense data is required
- Can You Consistently Keep Track of Column Labels Using Sklearn’s Transformer API?
- sklearn train_test_split on pandas stratify by multiple columns
- Apply StandardScaler to parts of a data set [duplicate]
- How do I convert a Pandas series or index to a NumPy array? [duplicate]
- Pandas dataframe get first row of each group
- Can anyone explain me StandardScaler?
- Forcing pandas .iloc to return a single-row dataframe?
- Scatter plots in Pandas/Pyplot: How to plot by category [duplicate]
- round a single column in pandas
- Floor or ceiling of a pandas series in python?
- Adding a new pandas column with mapped value from a dictionary [duplicate]
- group by week in pandas
- making matplotlib scatter plots from dataframes in Python’s pandas
- How to calculate 1st and 3rd quartiles?
- Read data from pyodbc to pandas
- Pandas replace a character in all column names
- How to apply a function on every row on a dataframe?
- how to replace an entire column on Pandas.DataFrame
- Feature/Variable importance after a PCA analysis
- How to set a variable to be “Today’s” date in Python/Pandas
- Reducing size of pyinstaller exe
- Difference between scikit-learn and sklearn (now deprecated)
- Constructing a co-occurrence matrix in python pandas
- pandas.read_csv from string or package data
- subsetting a Python DataFrame
- How to get scalar value on a cell using conditional indexing
- Pandas: Assigning multiple *new* columns simultaneously
- how to reset index pandas dataframe after dropna() pandas dataframe
- What is the process to create pdf reports with charts from a DB?
- Python pandas groupby aggregate on multiple columns, then pivot
- Split pandas dataframe in two if it has more than 10 rows