I have a .csv dataset with three columns formatted as follows
t X Y
0.040662 1.041667 1
0.139757 1.760417 2
0.144357 1.190104 1
0.145341 1.047526 1
0.145401 1.011882 1
0.148465 1.002970 1
Instead of manually writing it as
x_final = np.array([1.041667, 1.760417, 1.190104, 1.047526, 1.011882, 1.002970])
v_observations = np.array([1, 2, 1, 1, 1, 1])
I wanted to perform it automatically by copying the pandas dataframe to an array and here is my code
import numpy as np
from numpy.linalg import inv
import pandas as pd
df = pd.read_csv('testdata.csv')
print(df)
df.dropna(inplace=True)
X = df.drop('Y', axis=1)
y = df['Y']
time = df.drop('t', axis=1)
print(X)
d1= np.array([X])
d2 = np.array([y])
x_final = np.array([d1])
y_final = np.array([d2])
z = np.c_[x_final, y_final]
However, I am getting this error when I try to run my code.
ValueError: cannot copy sequence with size 6 to array axis with dimension 2
How can I fix this error?
z = df.dropna().drop('t', axis=1).valuesd1= np.array([X])before reaching there when i try to run it line by line.