Error while dividing two columns value in a dataframe - pyldavis

I am receiving an error while dividing two columns value in a dataframe. This is the code:
df['lose%'] = df['LostGames']/ df['PlayedGames']
This is my error:
TypeError: unsupported operand type(s) for /: 'str' and 'str'
Can anyone help me with this ??

df1.WonGames = pd.to_numeric(df1.WonGames)
df1.LostGames = pd.to_numeric(df1.LostGames)
df1.PlayedGames = pd.to_numeric(df1.PlayedGames)

Related

Plot values from a column on R

I have a shape file of data and I want to apply RK on values from only one column of my shp.
The column name is "Fabric" and contains these values:
V
S
M
I tried to separate the values using that, but I get an error:
pots = read.csv(file="C:\\Users\\HP\\folder\\Pots.csv", sep='\t')
pots #displays all columns and values
plot(subset(Pots,Fabric=="V"))
Error in h(simpleError(msg, call)) :
error in evaluating the argument 'x' in selecting a method for function 'plot': object 'Fabric' not found
Is there any other way to do this?

How to fix 'non-numeric argument to mathematical function'

I am totally new in R and doing an assignment for my studies. While coding I found an error stating "non-numeric argument to mathematical function". I Know the header is causing it, as it is the only non-numeric character in the database. But I don't know how to fix it.
I tried to calculate excluding the header, but couldn't do it.
DF = read.csv("Nominal Broad Dollar Index Modified.csv", header = TRUE)
head(DF)
This is the head of my data frame, & I'm not sure where the x1 column came and whether it is causing the error.
Index = DF$Index
Index0 = Index[DF$Y < 2018]
R0 = diff(log(Index0))
Error in log(Index0) : non-numeric argument to mathematical function
there are no results, I'm just getting errors.

length of 'center' must equal the number of columns of 'x'

I'm trying to scale a matrix in R.
I have:
maxs<- apply(rawsingle,2,max)
mins<- apply(rawsingle,2,min)
and then
scaledss<- scale(rawsingle,center=mins,scale = (maxs-mins))
I get the error:
'Error in scale.default(rawsingle, center = mins, scale = (maxs - mins)) :
length of 'center' must equal the number of columns of 'x''
Immediately following the error, I typed:
length(mins)==ncol(rawsingle)
and it returned TRUE, so I have no idea whats going on.
Has anyone had a similar issue before?
All the variables needs to be of type numeric:
dades[2:13] <- lapply(dades[2:13], as.numeric)
The problem was that some elements in 'rawsingle' were character strings due to an error in loading it.

CreateDataPartition gave me Error: 'data' must be of a vector type, was 'NULL'

I got below error while I was trying to use CreateDataPartition() function from caret package. Here y variable accepts vector and I'm passing a column from my data.frame. I hope it is in correct format. I still don't understand why it is giving me error.
My Code:
bikeInTrain<-createDataPartition(y=bikeTrainRaw$datetime, p=0.7,list = FALSE)
Error:
Error in matrix(unlist(out), ncol = times) :
'data' must be of a vector type, was 'NULL'
datetime column is of factor class. Should I change this to something else?
Let me know If I'm going wrong somewhere.

Error in if/while (condition) { : argument is of length zero

I received the error
Error in if (condition) { : argument is of length zero
or
Error in while (condition) { : argument is of length zero
What causes this error message, and what does it mean?
On further inspection it seems that the value is NULL.
condition
## NULL
In order to deal with this error, how do I test for NULL values?
I expected that this would return TRUE, but I got an empty logical value:
condition == NULL
## logical(0)
See ?NULL
You have to use is.null
‘is.null’ returns ‘TRUE’ if its argument is ‘NULL’ and ‘FALSE’
otherwise.
Try this:
if ( is.null(hic.data[[z]]) ) { print("is null")}
From section 2.1.6 of the R Language Definition
There is a special object called NULL. It is used whenever there is a need to indicate or
specify that an object is absent. It should not be confused with a vector or list of zero
length.
The NULL object has no type and no modifiable properties. There is only one NULL object
in R, to which all instances refer. To test for NULL use is.null. You cannot set attributes
on NULL.
What causes this error message, and what does it mean?
if statements take a single logical value (technically a logical vector of length one) as an input for the condition.
The error is thrown when the input condition is of length zero. You can reproduce it with, for example:
if (logical()) {}
## Error: argument is of length zero
if (NULL) {}
## Error: argument is of length zero
Common mistakes that lead to this error
It is easy to accidentally cause this error when using $ indexing. For example:
l <- list(a = TRUE, b = FALSE, c = NA)
if(l$d) {}
## Error in if (l$d) { : argument is of length zero
Also using if-else when you meant ifelse, or overriding T and F.
Note these related errors and warnings for other bad conditions:
Error in if/while (condition) {: missing Value where TRUE/FALSE needed
Error in if/while (condition) : argument is not interpretable as logical
if (NA) {}
## Error: missing value where TRUE/FALSE needed
if ("not logical") {}
## Error: argument is not interpretable as logical
if (c(TRUE, FALSE)) {}
## Warning message:
## the condition has length > 1 and only the first element will be used
How do I test for such values?
NULL values can be tested for using is.null. See GSee's answer for more detail.
To make your calls to if safe, a good code pattern is:
if(!is.null(condition) &&
length(condition) == 1 &&
!is.na(condition) &&
condition) {
# do something
}
You may also want to look at assert_is_if_condition from assertive.code.
When testing for NULL values, you want to use is.null(hic.data[[z]]).

Resources