replace() argument 1 must be str, not float [duplicate] - python

This question already has answers here:
Replace function not accepting list as argument - pandas. Getting error TypeError: replace() argument 1 must be str, not list
(1 answer)
TypeError: must be str, not float
(3 answers)
Python3 Typerror: replace() argument 1 must be str, not int
(2 answers)
Closed 16 days ago.
df=pd.read_json(('/content/Prescription Record.json').replace(np.nan,0), orient='records')
error:
TypeError Traceback (most recent call last)
<ipython-input-41-ca50d65018a4> in <module>
----> 1 df=pd.read_json(('/content/Prescription Record.json').replace(np.nan,0), orient='records')
TypeError: replace() argument 1 must be str, not float

Related

Why does the "lala" + int need a conversion to str but the "lala" * 2 doesn't? [duplicate]

This question already has answers here:
How to resolve TypeError: can only concatenate str (not "int") to str [duplicate]
(6 answers)
Closed 2 years ago.
This works,
In [2]:
"I said " + ("Hey " * 2) + "Hey!"
Out[2]:
'I said Hey Hey Hey!'
but this doesn't. Why?
In [3]:
"The correct answer to this multiple choice exercise is answer number " + 2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
"The correct answer to this multiple choice exercise is answer number " + 2
TypeError: must be str, not int
It's okay to multiply a string by an integer -- the result is N repetitions of the string.
I's not okay to add a string to an integer. The people who designed Python decided that this is not allowed.
That's just how Python works.

removing substring [duplicate]

This question already has answers here:
Keeping only certain characters in a string using Python?
(3 answers)
Closed 7 months ago.
Can someone please hint my mistake. Im trying to remove numbers from the string. Findall succefully finds the number but replace does not replace them with empty string. here is the code:
import re
x = 'John2345 can5 code with python3'
extra = re.findall('\d{1,9}', x)
x.replace(extra, '')
x
and here is the error:
TypeError Traceback (most recent call last)
<ipython-input-334-bfc161d88f65> in <module>()
2 x = 'ererf ergg5 erg 545 eeg'
3 extra = re.findall('\d{1,9}', x)
----> 4 x.replace(extra, '')
5 x
TypeError: Can't convert 'list' object to str implicitly
Cheers,
Sia
Use re.sub()
re.sub(r'\d+' ,'', x)
x is a string, extra is a list, right? The best hint is in the error message you recieved:
TypeError: Can't convert 'list' object to str implicitly
What python actually tells you, in human language is "I can't get your list object as argument here!! give me a string!!!"

How to fix "unsupported operand type(s)" in Python? [duplicate]

This question already has answers here:
How can I read inputs as numbers?
(10 answers)
Closed 6 months ago.
total=0
output=("enter next sales value")
sales=input
total_sales=total+sales
I keep getting this error:
Traceback (most recent call last): File "python", line 4, in TypeError: unsupported operand type(s) for +: 'int' and 'builtin_function_or_method'
You must use input() instead of input.
Moreover in python 3, the input() function returns a string, not an integer. So to use the return value in an addition, you must indicate it as an integer:
sales = input("Enter next sales value")
total_sales = total + int(sales)

TypeError: 'xxx' takes 1 positional argument but 2 were given [duplicate]

This question already has answers here:
"TypeError: method() takes 1 positional argument but 2 were given" but I only passed one
(10 answers)
Closed 6 years ago.
Hier was my first question: Name 'xxx' is not defined
And after edit I have this error:
self.view_splash(0)
TypeError: view_splash() takes 1 positional argument but 2 were given
What do I need to do, to fix it ?
def view_splash(arg1): is inside a class so you should use the staticmethod decorator
#staticmethod
def view_splash(arg1):

How to solve this error : TypeError: Can't convert 'int' object to str implicitly [duplicate]

This question already has answers here:
How can I read inputs as numbers?
(10 answers)
How can I concatenate str and int objects?
(1 answer)
Closed 7 years ago.
>>> g = input ("enter:")
enter: 50
>>> g + 100
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
g + 100
TypeError: Can't convert 'int' object to str implicitly
>>>
input ("enter:") returns string and you cannot add string and int as your error tells you
You must convert it to int type before
int(g) + 100

Categories

Resources