Reputation: 605
I am applying for loop to a column in python. But I am not able to execute it. It is producing error. I want square of a column. Please see where I am committing mistake. I know i can do this with lambda
. But I want to perform it in traditional way.
import pandas as pd
output=[]
for i in pd.read_csv("infy.csv"):
output.append(i['Close']**2)
print(output)
Upvotes: 0
Views: 44
Reputation: 113940
the whole point of pandas is not to loop
output = pd.read_csv("infy.csv")['Close']**2
Upvotes: 2