Python Forum
IndentationError: unexpected indent - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Data Science (https://python-forum.io/forum-44.html)
+--- Thread: IndentationError: unexpected indent (/thread-10142.html)



IndentationError: unexpected indent - Grin - May-14-2018

Hi All.

I'm trying to run some models on a dataset for college assignments and having a problem with the following commands. I'm typing them direct into the command line.

import pandas as pd
 import matplotlib.pyplot as plt
df= pd.read_csv ('/home/Documents/crypto-markets.csv')
df = pd.DataFrame([['bitcoin',BTC,Bitcoin,2013-04-28,1,135.3,135.98,132.1,134.21,0,1500520000,0.5438,3.88],
                  ['bitcoin',BTC,Bitcoin,2013-04-29,1,134.44,147.49,134,144.54,0,1491160000,0.7813,13.49]],
			columns=['slug',symbol,name,date,ranknow,open,high,low,close,volume,market,close_ratio,spread])
This is the error message

Error:
>>> import pandas as pd >>> df = pd.DataFrame([['bitcoin',BTC,Bitcoin,2013-04-28,1,135.3,135.98,132.1,134.21,0,1500520000,0.5438,3.88], File "<stdin>", line 1 df = pd.DataFrame([['bitcoin',BTC,Bitcoin,2013-04-28,1,135.3,135.98,132.1,134.21,0,1500520000,0.5438,3.88], ^ SyntaxError: invalid token >>> ['bitcoin',BTC,Bitcoin,2013-04-29,1,134.44,147.49,134,144.54,0,1491160000,0.7813,13.49]], File "<stdin>", line 1 ['bitcoin',BTC,Bitcoin,2013-04-29,1,134.44,147.49,134,144.54,0,1491160000,0.7813,13.49]], ^ IndentationError: unexpected indent >>> #columns=['slug',symbol,name,date,ranknow,open,high,low,close,volume,market,closer,spread]) ... columns=['slug',symbol,name,date,ranknow,open,high,low,close,volume,market,spread]) File "<stdin>", line 2 columns=['slug',symbol,name,date,ranknow,open,high,low,close,volume,market,spread]) ^ IndentationError: unexpected indent >>>



RE: IndentationError: unexpected indent - killerrex - May-14-2018

Please use [python][/python] and [error][/error] or the indentation is lost... and in this case seems like your error is precisely an indentation error.


RE: IndentationError: unexpected indent - Grin - May-15-2018

(May-14-2018, 10:39 PM)killerrex Wrote: Please use [python][/python] and [error][/error] or the indentation is lost... and in this case seems like your error is precisely an indentation error.

Hi Killerrex.

I've troubleshooted the error message and from my research it is down to the characters being greater the 8 bits in length, I've tried this on a couple of word in the index but it still finds an issue with my code. Any help much appreciated as usual. Smile


RE: IndentationError: unexpected indent - buran - May-15-2018

First of all - always post the code as it is, when produce the error. From the error message it's clear you use IDLE in interactive mode. And then you post a code snippet, not an interactive session. It's cumbersome to keep correct indentation with long lines in IDLE interactive mode, so don't do so - save the code as py file and run it.
Note that in your code you have incorrect indentation on line#2