Whas might be causing 'TypeError: can only concatenate str (not int) to str' when calculating correlation?
With a little help I was able to solve this, so I am posting an answer. Maybe someone will find it useful.
The problem was indeed related to datatypes. It was caused by non-numeric values in columns SMA14 and SMA50 (those were like 'nan5', 'nan6' etc, not just 'nan'). When checking data.info(), it stated that dtype for mentioned columns are 'Objects'. And we needed them to be float64 instead.
So here what needed to be done.
1). Fix the amounts ('nan5', 'nan6' etc)
to_fix = ('SMA14', 'SMA50')
for col in to_fix:
for el in data[col]:
if (type(el) != int) and (type(el) != float) and (el[0:3] == 'nan'):
index = data[data[col] == el].index.item()
data.at[index, col] = 0
I know there are other ways of doing it, but I've ran into troubles and ultimately what worked for me, was the above. Of course, it might be that I was doing something wrong.
2). Change the datatypes - and this is what I was missing when I asked the question.
data['SMA14'] = data['SMA14'].astype(float)
data['SMA50'] = data['SMA50'].astype(float)
Why does this error happen? TypeError: can only concatenate str (not int) to str
You are trying to add int
to string
try this
if a=="yes"or a=="y":
value1=random.randint(0,100)
choice1=input("Your Value is: \n"+str(value1)+ "\nYou would like to make it your Intelligence,Attack Or Defence level? ")
TypeError: can only concatenate str (not int) to str but when trying to change var's to str, I get a different error
I already fixed the problem. The problem being I needed to changeTime
andPieces
Tofloat(time)
andfloat(pieces)
and it works.
Python: TypeError: can only concatenate str (not int) to str : variable stored wrong
You can concate only strings, so before concate all your userinputs you must "convert" them into strings
Example1:
command1 = "RAMP " + " ".join(map(str, [userinput5, userinput1, userinput2, userinput4, userinput3]))
Example2:
command1 = f"RAMP {userinput5} {userinput1} {userinput2} {userinput4} {userinput3}"
Getting Can only concatenate str (not int) to str when adding to a value read from a file
When you read from a file with f.read, the information acquired is determined as a string, which is why when you try to add 1 to counter ( f.e 5 + 1), the program thinks you are trying to do something like this "5" + 1.
A simple fix would be to state that what you read from the file is an integer:
aaa = int(float(f.read()))
Related Topics
Complexity of *In* Operator in Python
Using Pickle.Dump - Typeerror: Must Be Str, Not Bytes
Why Doesn't a Python Dict.Update() Return the Object
Calculate Average of Every X Rows in a Table and Create New Table
Python Out of Memory on Large CSV File (Numpy)
Why Does Sys.Exit() Not Exit When Called Inside a Thread in Python
Calculate Mean Across Dimension in a 2D Array
How Include Static Files to Setuptools - Python Package
How to Convert Columns into One Datetime Column in Pandas
How to Remove Packages Installed with Python's Easy_Install
Custom Filter in Django Admin on Django 1.3 or Below
Format Floats with Standard JSON Module
Transparent Background in a Tkinter Window