Python Forum
Thread Rating:
  • 1 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Indentationerror
#1
Hi there
I have followed error:
Indentationerror: unindent does not match any outer indentation level


It is all about this line: if weekday != 'all': and this one: if month != 'all':

in this statement:
df = pd.read_csv(CITY_DATA[city])
def main():
    while True: city, month, weekday
        #For weekday
    df = load_data(city, month, weekday)
        # TO DO: display the most common month
     #convert start time into datetime
    df['Start Time'] = pd.to_datetime(df['Start Time'])
    #create a month column
    df['month'] = df['Start Time'].dt.month

    df['day_of_week'] = df['Start Time'].dt.weekday_name
    if weekday != 'all':
        # filter by day of week to create the new dataframe
        df = df[df['day_of_week'] == weekday.title()]
            
             # filter by month if applicable
     if month != 'all':
        # use the index of the months list to get the corresponding int
        months = ['January', 'February', 'March', 'April', 'May', 'June']
        month = months.index(month) + 1
if __name__ == "__main__":
    main()
How can I fix this?
Reply


Messages In This Thread
Indentationerror - by Jack_Sparrow - May-15-2018, 05:41 PM
RE: Indentationerror - by wavic - May-15-2018, 05:43 PM
RE: Indentationerror - by Jack_Sparrow - May-15-2018, 06:10 PM
RE: Indentationerror - by wavic - May-15-2018, 06:20 PM
RE: Indentationerror - by Jack_Sparrow - May-16-2018, 05:50 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  IndentationError: unexpected indent dee 3 2,393 May-02-2022, 02:15 AM
Last Post: dee
  error "IndentationError: expected an indented block" axa 4 2,971 Sep-08-2020, 02:09 PM
Last Post: ibreeden
  IndentationError: unexpected indent jk91 1 2,410 Feb-27-2020, 08:56 PM
Last Post: buran
  IndentationError jagannath 1 2,506 Nov-04-2019, 07:41 AM
Last Post: buran
  IndentationError: expected an indented block ryder5227 2 2,643 Sep-27-2019, 06:59 PM
Last Post: jefsummers
  IndentationError on installed package evvvonder 3 3,079 Jun-29-2019, 10:30 PM
Last Post: Gribouillis
  how do i fix this problem - IndentationError? GrandMaster101 8 7,794 Apr-04-2019, 09:38 PM
Last Post: carloszoom3000
  IndentationError message could be confusing to new programmers insearchofanswers87 1 2,376 May-16-2018, 05:05 PM
Last Post: Larz60+
  IndentationError: unexpected indent (Python) segs 8 17,430 Aug-11-2017, 03:13 PM
Last Post: segs

Forum Jump:

User Panel Messages

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