I have .csv file with colums A and B, and rows with values.
A, | B |
---|---|
232.65, | -57.48 |
22.69, | -5.46 |
23.67, | -7.71 |
I want to loop these values with function.
So lets create simple function with 2 positional parameters:
def add_numbers(n1, n2):
answer = n1+n2
print(answer)
#lets read the file:
import pandas as pd
df= pd.read_csv(r'myfile.csv')
print(df[A]) #just checking the column A for this example, but column B is also required for n2.
0 232.65
1 22.69
3 23.67
- I could also transfer those colums to array but I still could not loop it. How would I loop these with the function that requires two arguments?
arr = np.loadtxt(r'myfile.csv', delimiter=',')
arr
array([[232.65, -57.48],
[22.69, -5.46],
[23.67, -7.71],
I have been trying to loop with various ways and iter and enumerate and apply, but I keep doing something slightly wrong.
Cheer, Joonatan