Here's what i have so far:
data.shape: # data == my dataframe
(768, 9)
data2 = pd.DataFrame(data) # copy of data
array = data.values # convert data to arrays
X = array[:,0:8]
Y = array[:,8]
# perform a transformation on X
Xrescaled = scaler.transform(X)
How can i replace each column of the dataframe, data2
with the corresponding column in the array, Xrescaled
? Thanks.
You can just do: data2.iloc[:,:8] = Xrescaled
, here is a demo:
import numpy as np
data = pd.DataFrame({'x': [1,2], 'y': [3,4], 'z': [5,6]})
data
# x y z
#0 1 3 5
#1 2 4 6
import pandas as pd
data2 = pd.DataFrame(data)
data2
# x y z
#0 1 3 5
#1 2 4 6
X = data.values[:,:2]
Xrescaled = X * 2
Xrescaled
# array([[2, 6],
# [4, 8]])
data2.iloc[:,:2] = Xrescaled
data2
# x y z
#0 2 6 5
#1 4 8 6
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With