Python Forum
IndentationError: unexpected indent
Thread Rating:
  • 2 Vote(s) - 2.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
IndentationError: unexpected indent
#1
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 >>>
Reply
#2
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.
Reply
#3
(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
Reply
#4
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
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  indent error metalray 2 3,196 Apr-16-2018, 04:39 PM
Last Post: metalray
  IndentationError when no problem with indentation BobLoblaw 10 8,725 Nov-02-2017, 03:20 AM
Last Post: nilamo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020