data-manipulation

Python - Pandas: number/index of the minimum value in the given row

倖福魔咒の 提交于 2021-02-10 13:49:13
问题 I have one pandas dataframe, with one row and multiple columns. I want to get the column number/index of the minimum value in the given row. The code I found was: df.columns.get_loc('colname') The above code asks for a column name. My dataframe doesn't have column names. I want to get the column location of the minimum value. 回答1: Use argmin with converting DataFrame to array by values, only necessary only numeric data: df = pd.DataFrame({ 'B':[4,5,4,5,5,4], 'C':[7,8,9,4,2,3], 'D':[1,3,5,7,1

Python - Pandas: number/index of the minimum value in the given row

心不动则不痛 提交于 2021-02-10 13:49:09
问题 I have one pandas dataframe, with one row and multiple columns. I want to get the column number/index of the minimum value in the given row. The code I found was: df.columns.get_loc('colname') The above code asks for a column name. My dataframe doesn't have column names. I want to get the column location of the minimum value. 回答1: Use argmin with converting DataFrame to array by values, only necessary only numeric data: df = pd.DataFrame({ 'B':[4,5,4,5,5,4], 'C':[7,8,9,4,2,3], 'D':[1,3,5,7,1

R: Plot not Fully Loading

…衆ロ難τιáo~ 提交于 2021-02-05 10:49:07
问题 I am working the R programming language. I am trying to follow this tutorial over here: https://plotly.com/r/parallel-coordinates-plot/ I am trying to make a "parallel coordinate plot" of the famous iris data set. Instead of loading the iris data set through the github link, I tried to use the built in iris data set that is available in R: #load library library(plotly) #load data data(iris) df = iris #make plot fig <- df %>% plot_ly(type = 'parcoords', line = list(color = ~Species, colorscale

R: Plot not Fully Loading

核能气质少年 提交于 2021-02-05 10:49:01
问题 I am working the R programming language. I am trying to follow this tutorial over here: https://plotly.com/r/parallel-coordinates-plot/ I am trying to make a "parallel coordinate plot" of the famous iris data set. Instead of loading the iris data set through the github link, I tried to use the built in iris data set that is available in R: #load library library(plotly) #load data data(iris) df = iris #make plot fig <- df %>% plot_ly(type = 'parcoords', line = list(color = ~Species, colorscale

Split Strings into values in long dataframe format [duplicate]

|▌冷眼眸甩不掉的悲伤 提交于 2021-02-05 09:42:02
问题 This question already has answers here : Split comma-separated strings in a column into separate rows (6 answers) Split delimited strings in a column and insert as new rows [duplicate] (6 answers) Closed 3 years ago . I have a dataframe that looks like the following example df which consist of a character variable VAR . df<-data.frame(ID = 1:2, VAR = c("VAL1\r\nVAL2\r\nVAL8","VAL2\r\nVAL5"), stringsAsFactors = FALSE) # ID VAR # 1 1 VAL1\r\nVAL2\r\nVAL8 # 2 2 VAL2\r\nVAL5 I would like to split

How to get value of last non-NA column [duplicate]

≡放荡痞女 提交于 2021-02-05 08:38:13
问题 This question already has answers here : Extract last non-missing value in row with data.table (5 answers) Closed 7 months ago . A bit difficult to explain, but I have a dataframe with values that look like a staircase - for every date, there are different columns that have NA for some dates. I want to create a new column that has the last non-NA column value in it. Hopefuly it makes more sense with this example: Sample dataframe: test <- data.frame("date" = c(as.Date("2020-01-01"), as.Date(

How to get value of last non-NA column [duplicate]

徘徊边缘 提交于 2021-02-05 08:37:29
问题 This question already has answers here : Extract last non-missing value in row with data.table (5 answers) Closed 7 months ago . A bit difficult to explain, but I have a dataframe with values that look like a staircase - for every date, there are different columns that have NA for some dates. I want to create a new column that has the last non-NA column value in it. Hopefuly it makes more sense with this example: Sample dataframe: test <- data.frame("date" = c(as.Date("2020-01-01"), as.Date(

R: Parallel Coordinates Plot without GGally

倖福魔咒の 提交于 2021-02-05 08:09:56
问题 I am using the R programming language. I am using a computer that does not have a USB port or an internet connection - I only have R with a few preloaded libraries (e.g. ggplot2, reshape2, dplyr, base R). Is it possible to make "parallel coordinate" plots (e.g. below) using only the "ggplot2" library and not "ggally"? #load libraries (I do not have GGally) library(GGally) #load data (I have MASS) data(crabs, package = "MASS") #make 2 different parallel coordinate plots ggparcoord(crabs)

Extract values from data frame using data frame of indexes - R

孤者浪人 提交于 2021-02-05 06:59:05
问题 I have a data frame of useful information: X = c(1,2,3,4,5,6,7,8,9,10) Y = c(5,4,3,2,1,0,1,2,3,4) Z = c(11,12,13,14,15,16,17,18,19,20) df <- data.frame(X, Y, Z) And a data frame of row and column positions: row <- c(6,2,5) column <- c(1,2,3) pos <- data.frame(row, column) I would like to use some function ( fun ) that uses the column and row positions in pos to return the values in df occupying those positions, e.g. fun(df, pos$row, pos$column) [1] 6 4 15 I thought I could do it like this,

summary stats across columns, where column names indicate groups

﹥>﹥吖頭↗ 提交于 2021-02-04 16:35:48
问题 Data frame have includes a few thousand vectors that follow a naming pattern. Each vector name includes a noun, then either _a , _b , or _c . Below are the first 10 vars and obs: id turtle_a banana_a castle_a turtle_b banana_b castle_b turtle_c banana_c castle_c A -0.58 -0.88 -0.56 -0.53 -0.32 -0.42 -0.52 -0.89 -0.72 B NA NA NA -0.84 -0.36 -0.26 NA NA NA C 0.00 -0.43 -0.75 -0.35 -0.88 -0.14 -0.26 -0.15 -0.81 D -0.81 -0.63 -0.77 -0.82 -0.83 -0.50 -0.77 -0.25 -0.07 E -0.25 -0.33 -0.09 -0.51 -0