0

Recently I started learning python. I want to define a function for columns in data frame. I want square of every value in column. Please check this code. It results in error in fifth line.

def new_fun(df,col_name='Open'): out = [] col=df[col_name] for element in col: out[element].append(element**2) return out 

1 Answer 1

1

Python is its use of indentation to highlight the blocks of code. All statements with the same distance to the right belong to the same block of code. If a block has to be more deeply nested, it is simply indented further to the right.

You need to more indented in 5th line.

def new_fun(df,col_name='Open'): out = [] col=df[col_name] for element in col: out[element].append(element**2) return out 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.