# data analysis EDA issues, indent or type

I am a newbie in DS world, right now i am working on some EDA practice, and run into an issue here.

Here is my code:

## Convert some columns to numeric values

for column in cols:
auto[column] = pd.to_numeric(auto[column]
return auto



1. error 1: File "", line 4 return auto ^ SyntaxError: 'return' outside function

I tried to change return's indent:

## Convert some columns to numeric values

for column in cols:
auto[column] = pd.to_numeric(auto[column])
return auto



1. error 2: TypeError Traceback (most recent call last) in () 1 ## Convert some columns to numeric values 2 for column in cols: ----> 3 auto[column] = pd.to_numeric(auto[column]) 4 return auto 5

TypeError: 'function' object is not subscriptable

Can anyone help me understand what went wrong here?

Thanks

• Please use four spaces indenting to get code as-is. Your formatting is impossible to read, and in Python indenting is important. – Adrian Keister Sep 12 '18 at 19:21
• Also, are you trying to use a list comprehension? Or is this inside of some function definition? List comprehensions don't use the return statement. – Adrian Keister Sep 12 '18 at 19:22
• how can i show the indent here? when i copied my code, there are indents, but when i save, the indents are gone. Just now i also tried to edit, i checked out in the 'advanced help', seems like use '-' should mean indent 4, '*' should mean indent 8, i add these in my code, still not showing the indent. – user633599 Sep 12 '18 at 20:21
• If you indent four spaces, you get the code environment. All further indenting inside that will be preserved. Every line of code should start with four spaces. – Adrian Keister Sep 12 '18 at 20:24
• Yeah, finally the indents showing here. Can u take a look now? – user633599 Sep 12 '18 at 20:29

Try something like this (the function also needs to know what cols is - perhaps pass that in as another parameter?):

def read_auto_data(auto):
for column in cols:
auto[column] = pd.to_numeric(auto[column])
return auto


• Let me try, i will let u know if it works or not ASAP. – user633599 Sep 12 '18 at 20:54
• i just tried, it is true, when i put the function together, it works. I previously have defined the function already, but the indent might get messed up since there is a lot of code in between. thank you very much – user633599 Sep 12 '18 at 22:08
• You're very welcome! Glad I could be of help. – Adrian Keister Sep 12 '18 at 23:27