Home > Net >  A given column is not a column of the dataframe
A given column is not a column of the dataframe

Time:11-30

I'm trying to fit a module to my dataframe but im getting A given column is not a column of the dataframe error. please take a look at my codes below:

import tensorflow as tf
import pandas as pd
import matplotlib.pyplot as plt
from sklearn.compose import make_column_transformer
from sklearn.preprocessing import MinMaxScaler, OneHotEncoder
from sklearn.model_selection import train_test_split
houseprice = pd.read_csv('houseprice.csv')
houseprice = houseprice.drop("Price", axis=1)
print(houseprice)

the outcome of the Print(houseprice) is this: enter image description here

here is the rest of my code that i'm getting the error in this part

houseprice_one_hot = pd.get_dummies(houseprice)

# creating X and y (test set and train set)
ct = make_column_transformer(
    (MinMaxScaler(), ["Area", "Room"]),
    (OneHotEncoder(handle_unknown="ignore"), ["Parking", "Warehouse", "Elevator", "Address"])
)

X = houseprice_one_hot.drop("Price(USD)", axis=1)
y = houseprice_one_hot["Price(USD)"]
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

ct.fit(X_train)

and here is a picture of my error (im trying to compile it in google colab but im getting this error in vscode too): enter image description here

I would appreciate if someone can help me

CodePudding user response:

I believe you spelt elevator wrong within your ct variable.

ct = make_column_transformer(
    (MinMaxScaler(), ["Room", "Area"]),
    (OneHotEncoder(handle_unknown="ignore"), ["Parking", "Warehouse", **"Elevatour"**, "Address"])

CodePudding user response:

Anyone who has same problem, i did change my code and it did work correctly.

please check the link below:

could not convert string to float: '2,550,000,000'

  • Related