r

Pandas or R – Merge Rows By Same Value in Column Over NaN values – Look at Example

Pandas or R – Merge Rows By Same Value in Column Over NaN values – Look at Example Question: I have a very specific dataset it looks something like this: record_id event_id instrument repeat_inst PI0005 v03_abc_1 NaN 1 PI0005 v03_abc_1 i_sensor NaN PI0005 v03_abc_1 NaN NaN PI0005 v02_abc_33 i_sensor NaN PI0005 v02_abc_33 NaN NaN PI0006 …

Total answers: 1

R Tidyverse Alternative Code in Python for data wrangling

R Tidyverse Alternative Code in Python for data wrangling Question: I am trying to do the following in Python: Import iris data base create a new column with the name target_measure that will be the multiplication of the natural log of Sepal.Width times the squeared Petal.Width create a new variable called categorical_measure that will clasify …

Total answers: 1

Is there a way to mimic the pipe operator from R in Python?

Is there a way to mimic the pipe operator from R in Python? Question: See the example below. Is it possible to put each Python operation on a new line? If I have many operations, the code is not all visible. I need to scroll the VS Code window to the right. Thanks # R …

Total answers: 1

Reference parameter in figure caption with Quarto

Reference parameter in figure caption with Quarto Question: Is there a way to reference a parameter in a Quarto figure or table caption? In the example below, I am able to reference my input parameter txt in a regular text block, but not in a figure caption. In the figure caption, only the raw text …

Total answers: 1

Function equivalent to (python) seaborn's "set_context()" in (R) ggplot2?

Function equivalent to (python) seaborn's "set_context()" in (R) ggplot2? Question: A quite neat function of python’s library seaborn is to be able to all the sizes of the plots, labels and the majority of graph elements with a single command: set_context(context), for different contexts the sizes of figures are resized accordingly, so if context is …

Total answers: 1

Rs mutate() and grepl() in Python

Rs mutate() and grepl() in Python Question: I have a column in a dataset that lists all of the softwares that a given computer has installed. I have created multiple binary columns from this column so each software has its own column. My R code is below: data <- data %>% mutate(MS_Office_installed = ifelse(grepl("MS Office", …

Total answers: 1

Rearranging a list to get the 2nd column entries as rows

Rearranging a list to get the 2nd column entries as rows Question: I have a list associated to strings as follows; A string1^description1`string2^description2`string3^description3 B string4^description4 C string1^description1`string5^description5`string3^description3 D . E string6^description6`string1^description1 F string7^description7 G string1^description1`string4^description4`string5^description5 I would like to switch the first and second columns so that the stings in the 2nd column are the …

Total answers: 3

Pandas dropping na within conditions

Pandas dropping na within conditions Question: if i have the following input participant trials Correct_Choice Opt_in 1 1 NaN 1 1 1 1 NAN 2 1 NaN 1 2 1 0 NaN My desired output is participant trials Correct_Choice Opt_in 1 1 1 1 2 1 0 1 What is the best way to do …

Total answers: 1

Rewriting functions from r to python

Rewriting functions from r to python Question: I have function written in R. V <- function(c, E, HS, EC_50) E + (1 – E) / (1 + exp(HS * (c – EC_50)) I would like to get the same function in Python but I don’t know how. I haven’t used Python very much before. Therefore, …

Total answers: 2