0

after spliting x_train ,y_train .

x_train, x_test, y_train, y_test = train_test_split(X, Y, test_size = 0.3)
print(x_train.shape,y_train.shape)
(354, 13) (354,)

Again I need to join ytrain column to xtrain .Price is new column

x_train['Price']=y_train but this does not work

I am trying to use iloc like following but it gives warning

x_train['price']=y_train.iloc[0:354]

please help me out regarding this

StupidWolf
  • 45,075
  • 17
  • 40
  • 72
jyoti
  • 23
  • 4

1 Answers1

0

You get that warning because x_train is a view of X. Using an example:

df = pd.DataFrame(np.random.uniform(0,1,(100,4)),
columns=['x1','x2','x3','y'])
X = df[['x1','x2','x3']]
Y = df[['y']]

x_train, x_test, y_train, y_test = train_test_split(X, Y, test_size = 0.3)

You can see:

x_train._is_view
True

If I try to run your code, I get the same warning.

See this post about views of a data frame and also this on dealing with the warning. What you can do make a copy if you don't think it's an issue:

x_train = x_train.copy()
x_train['Price'] = y_train

Or use insert:

x_train.insert(x_train.shape[1],"Price",y_train)
StupidWolf
  • 45,075
  • 17
  • 40
  • 72