Python Forum
New to Pandas. I need help fixing a TypeError
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
New to Pandas. I need help fixing a TypeError
#1
I loaded a CSV file called 'IMDb movies.csv' from kaggle. Here is the link to this file https://www.kaggle.com/stefanoleone992/i...ve-dataset. I am just trying to reinforce what I learned about DataFrames and some basic commands. Down below I pasted my code. The problem is that I am getting a TypeError "TypeError: '>=' not supported between instances of 'str' and 'int'". I do not know why. It is coming from this line
year_before_1970 = movies_df[movies_df['year'] >= 1970]
. However, the line below, I do something similar like such
print(movies_df[movies_df['avg_vote'] >= 8.6].head(3))
and it doesn't give me an error. Can someone please help me figure out what went wrong.

import pandas as pd

movies_df = pd.read_csv('IMDb movies.csv')

#prints the first 5 rows of Dataset
print('***********************************\nFirst 5 rows\n',movies_df.head(), '\n***********************************')

#selects the columns headers of the Dataset
col = movies_df.columns
print('Headers of Dataset\n', col, '\n***********************************')

#which year produced the most movies
most_movies_yearly = movies_df.groupby('year').imdb_title_id.count().reset_index()
print(most_movies_yearly)

# movies were produced before the year 1970
year_before_1970 = movies_df[movies_df['year'] >= 1970]
print(year_before_1970)
Reply


Messages In This Thread
New to Pandas. I need help fixing a TypeError - by kramon19 - Dec-30-2020, 03:53 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [pandas] TypeError: list indices must be integers or slices, not str but type is int. cspower 4 982 Dec-30-2023, 09:38 AM
Last Post: Gribouillis
  I need help fixing a syntax error! chenqin348 5 4,258 Dec-27-2019, 12:07 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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