Python Forum
TypeError: unsupported operand type(s) for -: 'str' and 'str'
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
TypeError: unsupported operand type(s) for -: 'str' and 'str'
#2
import os
import pandas as pd
import numpy as np
import matplotlib as mlt
import csv


os.chdir("F:\Data Science\python program")


df=pd.read_csv("IMDB_data.csv",encoding='cp1252',skiprows=[2])


IMDB_Genre= df['Genre'].value_counts().to_frame().T


df.sort_values("Genre", axis = 0, ascending = True, 
                 inplace = True, na_position ='last') 


df['imdbRating']=pd.to_numeric(df['imdbRating'], errors='ignore',downcast='integer')
df['imdbVotes']=pd.to_numeric(df['imdbVotes'], errors='ignore',downcast='integer')


df['imdbVotes']=pd.to_numeric(df['imdbVotes'], errors='ignore',downcast='integer')
Error:
*​--------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-9-b8c9307b8a6b> in <module> ----> 1 df['dif_and_sq']=int(df['imdbRating']).sub(int(df['imdbVotes'])) C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\series.py in wrapper(self) 91 return converter(self.iloc[0]) 92 raise TypeError("cannot convert the series to " ---> 93 "{0}".format(str(converter))) 94 95 wrapper.__name__ = "__{name}__".format(name=converter.__name__) TypeError: cannot convert the series to <class 'int'>* df['dif_and_sq']=df['imdbRating'].values-df['imdbVotes'].values *--------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-16-00740a4575a9> in <module> ----> 1 df['dif_and_sq']=df['imdbRating'].values-df['imdbVotes'].values TypeError: unsupported operand type(s) for -: 'str' and 'str'
Reply


Messages In This Thread
RE: TypeError: unsupported operand type(s) for -: 'str' and 'str' - by Balaji - Oct-11-2019, 07:16 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Type Error: Unsupported Operand jhancock 2 1,196 Jul-22-2023, 11:33 PM
Last Post: jhancock
  TypeError: unsupported operand type(s) for +: 'dict' and 'int' nick12341234 1 9,330 Jul-15-2022, 04:04 AM
Last Post: ndc85430
  TypeError: unsupported opperand type(s) for %: 'int' and 'list' cool_person 7 2,175 May-07-2022, 08:40 AM
Last Post: ibreeden
  unsupported operand type(s) for %: 'list' and 'int' RandomCoder 4 32,883 May-07-2022, 08:07 AM
Last Post: menator01
  You have any idea, how fix TypeError: unhashable type: 'list' lsepolis123 2 3,013 Jun-02-2021, 07:55 AM
Last Post: supuflounder
  TypeError: __str__ returned non-string (type tuple) Anldra12 1 7,414 Apr-13-2021, 07:50 AM
Last Post: Anldra12
  unsupported operand type(s) for /: 'str' and 'int' Error for boxplot soft 1 3,068 Feb-09-2021, 05:40 PM
Last Post: soft
  TypeError: 'type' object is not subscriptable Stef 1 4,533 Aug-28-2020, 03:01 PM
Last Post: Gribouillis
  TypeError: unhashable type: 'set' Stager 1 2,613 Jun-08-2020, 04:11 PM
Last Post: bowlofred
  TypeError: __repr__ returned non-string (type dict) shockwave 0 3,197 May-17-2020, 05:56 PM
Last Post: shockwave

Forum Jump:

User Panel Messages

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