Splitting dataframe with not just words

Say I have df as follows: MyCol Red Motor Blue Taxi Green Taxi-1 Light blue small Taxi-1 Light blue big Taxi-2 I would like to split the color and the vehicle into two columns. I used this command to split the last word (could be any character). The last word (could be any character, like… Read More Splitting dataframe with not just words

What is causing "No non-missing arguments to max; returning -Inf"?

I have a function which will draw specific lines on my plot, defined as MaxLines <- function(df,df_col_1,df_col_2){ data.frame(df_col_1 = c(rep(df$df_col_1[which.max(df$df_col_2)], 2), -Inf), df_col_2 = c(-Inf, rep(max(df$df_col_2), 2))) } When I try to call this function I get the error mentioned in the title. col_1 = c(5,6,7) col_2 = c(1,2,3) foo <- data.frame(col_1,col_2) MaxLines(foo,col_1,col_2) ———————————————— new_1… Read More What is causing "No non-missing arguments to max; returning -Inf"?

PYTHON (PANDAS) Concatenate content of two rows on the last of these two rows

I’m struggling on concatenations of content of two rows into the last of these two rows. Here my situation: A B C D NaN NaN Rossi Brambilla Federico Giovanni Giorgio Marcello I would like something like A B C D NaN NaN Rossi Brambilla Federico Giovanni Rossi Giorgio Brambilla Marcello Could you please help me… Read More PYTHON (PANDAS) Concatenate content of two rows on the last of these two rows

Create a new column by extracting the smallest tuple from a data frame column

I have a dataframe with a column that contains tuples. I would like to create a new column that extracts the smallest tuple from the tuple column. What I have tried so far mydataframe[‘min_values’] = mydataframe[‘tuple_column’].apply(lambda x: min(x)) This above approach seems to work when I have at least 2 tuples, but it fails when… Read More Create a new column by extracting the smallest tuple from a data frame column

Count number of times the content of two columns are equal and different in dataframe in R

I have this dataframe df <- structure(list(`Prediction (Ge)` = c("Paranthropus", "Paranthropus", "Homo", "Paranthropus", "Australopithecus", "Paranthropus", "Paranthropus", "Australopithecus", "Paranthropus", "Australopithecus", "Paranthropus", "Australopithecus", "Australopithecus", "Australopithecus", "Australopithecus", "Paranthropus", "Homo", "Australopithecus", "Paranthropus", "Paranthropus", "Paranthropus", "Paranthropus", "Australopithecus", "Paranthropus", "Australopithecus", "Paranthropus", "Australopithecus"), `Prediction (Sp)` = c("Australopithecus africanus", "Paranthropus robustus", "Paranthropus boisei", "Paranthropus robustus", "Paranthropus robustus", "Paranthropus robustus", "Paranthropus robustus", "Australopithecus afarensis",… Read More Count number of times the content of two columns are equal and different in dataframe in R

How to randomly split grouped dataframe in python

I have the next dataframe: df = pd.DataFrame({ "player_id":[1,1,2,2,3,3,4,4,5,5,6,6], "year" :[1,2,1,2,1,2,1,2,1,2,1,2], "overall" :[20,16,7,3,8,80,20,12,9,3,2,1]}) what is the easiest way to randomly sort it grouped by player_id, e.g. player_id year overall 4 1 80 4 2 20 1 1 20 1 2 16 … … … And then split it 80-20 into a train and testing set… Read More How to randomly split grouped dataframe in python