I'm new to python and I'm practicing csv data operation. Now I have a situation where I have 100 * 4 datas where the i-th row corresponds to i-th example (x_i, y_i) Columns 1,2, and 3 are for each input variable (x_1, x_2, 1) abd 4-th column is output y. Then, determine appropriate constants (a,b) (Let's say (6, 5) here).
Now I want to draw graphs, the x-axis being ax_1+bx_2 and y-axis being y.
here are the parts of the datas.
"x1","x2","1","y"
-0.626453810742332,-0.620366677224124,1,0.28239638205273
0.183643324222082,0.0421158731442352,1,1.73290072129656
-0.835628612410047,-0.910921648552446,1,-0.293950695808836
and here is the code im trying to complete
import numpy as np
import matplotlib.pyplot as plt
if __name__ == '__main__':
x1 = []
x2 = []
y = []
a = 6
b = 5
with open('data.csv', 'r') as f:
lines = f.readlines()
tmp_x1 = np.array(lines)[:,0]
tmp_x2 = np.array(lines)[:,1]
tmp_y = np.array(lines)[:,3]
x1.append(tmp_x1)
x2.append(tmp_x2)
y.append(tmp_y)
ax1 = list()
bx2 = list()
for i in range(100):
ax1.append(a * x1)
bx2.append(b * x2)
plt.figure()
plt.xlabel('a*x1 + b*x2')
plt.ylabel('y')
plt.plot(ax1 + bx2, y)
and this code gives me error
IndexError: too many indices for array
Can someone help me to solve this?
[edit][graph]1
code:
import pandas as pd
import matplotlib.pyplot as plt
df = pd.read_csv('data.csv')
a,b = 6,5
df['x'] = df['x1']*a + df['x2']*b
plt.figure()
plt.plot(df['x'], df['y'])
plt.show()

