dataframe

How can I sum vectors nested in a column of a data frame?

依然范特西╮ 提交于 2021-02-08 06:46:40
问题 I have a data frame where one column contains a list. I want to convert the list to numeric and sum the values into a new column. Each row has a column with a vector like this: c("47", "39", "1") The new column would contain the sum of those numbers and would look like this: List SumList c("47", "39", "1") 87 c("11", "11") 22 c("1", "2") 3 I have tried a couple different approaches, but nothing seems to produce the outcome I need. Example data frame: DF <- structure(list(list = structure(list

How can I sum vectors nested in a column of a data frame?

南楼画角 提交于 2021-02-08 06:46:35
问题 I have a data frame where one column contains a list. I want to convert the list to numeric and sum the values into a new column. Each row has a column with a vector like this: c("47", "39", "1") The new column would contain the sum of those numbers and would look like this: List SumList c("47", "39", "1") 87 c("11", "11") 22 c("1", "2") 3 I have tried a couple different approaches, but nothing seems to produce the outcome I need. Example data frame: DF <- structure(list(list = structure(list

How to transform a dataframes row into columns in R?

送分小仙女□ 提交于 2021-02-08 06:43:30
问题 I have a data frame which I need to transform. I need to change the rows into unique columns based on the value of a column. ex: The Input DataFrame | column_1 | column_2 | ----------------------- | A | B | | A | C | | B | E | | B | C | | C | F | | C | G | The Output DataFrame | column_1 | column_2 | column_3 | ---------------------------------- | A | B | C | | B | E | C | | C | F | G | The final DataFrame should have all the unique values in column_1 and the values from column_2 from input

Pandas error: Writing as Excel with a MultiIndex is not yet implemented

守給你的承諾、 提交于 2021-02-08 06:40:55
问题 I have a pandas data frame that I create as follows: stats_matrix= #A list containing my data myindex=['','event 1','event 2','event 3','event 4','event 5','event 6','event 7','event 8','event 9','event 10'] #List used for indexing rows column_names=['Failed 1st Stage','% Failed 1st Stage','Active 1st Stage','% Active 1st Stage','Failed 2nd Stage','% Failed 2nd Stage','Failed 1st & 2nd','% Failed 1st & 2nd','Active 2nd Stage','% Active 2nd Stage','Total failed','% Total failed ','Total active

Summing columns in Dataframe that have matching column headers

試著忘記壹切 提交于 2021-02-08 06:22:08
问题 I have a dataframe that currently looks somewhat like this. import pandas as pd In [161]: pd.DataFrame(np.c_[s,t],columns = ["M1","M2","M1","M2"]) Out[161]: M1 M2 M1 M2 6/7 1 2 3 5 6/8 2 4 7 8 6/9 3 6 9 9 6/10 4 8 8 10 6/11 5 10 20 40 Except, instead of just four columns, there are approximately 1000 columns, from M1 till ~M340 (there are multiple columns with the same headers). I wanted to sum the values associated with matching columns based on their index. Ideally, the result dataframe

Shuffle a data frame while maintaining order with another data frame

我怕爱的太早我们不能终老 提交于 2021-02-08 05:55:23
问题 I have 2 data frames train and label . The data frame train has 784 rows and 20K columns. The data frame label has 1 row and 20K columns. Each i column in label corresponds to i column in train . train is something like: ---->--- 20K Columns ----> 0 0 0 0 ... 3 1 0 . . ... . 4 0 9 7 . . . . . . 1 4 So for each i column where i belongs to {1,20K} there is a corresponding label in the label data frame which is something like: ---->----20K columns-----> 0 -1 3 4 5 8 0 -5 -9 1 2 .... The first

rbinding a list of data frame R with NULL

走远了吗. 提交于 2021-02-08 05:44:49
问题 I have a list of data frame structure like this: Lets call this list listA: $ :'data.frame': 1 obs. of 3 variables: ..$ a :chr a1 ..$ b :chr b1 ..$ c :chr c1 $ : NULL $ :'data.frame': 1 obs. of 3 variables: ..$ a :chr a3 ..$ b :chr b3 ..$ c :chr c3 How do I preserves the order of the data, keeping the record NULL with either NA and form a data frame like this? a b c 1: a1 b1 c1 2: NA NA NA 3: a3 b3 c3 I have tried to use: listA <- data.frame(do.call(rbind, listA)) but the end result will skip

R move index column to first column [duplicate]

妖精的绣舞 提交于 2021-02-08 05:16:58
问题 This question already has answers here : Convert row names into first column (7 answers) Closed 4 years ago . I have following data frame: RMSE A 0.03655830 B 0.24513014 C 0.02009853 D 0.02223135 I want to move column that has A,B,C,D to be the first column and add an index to the data.frame. 回答1: try this: df <- cbind(newColName = rownames(df), df) rownames(df) <- 1:nrow(df) hope this is what you meant, the result will be: newColName RMSE 1 A 0.03655830 2 B 0.24513014 3 C 0.02009853 4 D 0

R move index column to first column [duplicate]

六眼飞鱼酱① 提交于 2021-02-08 05:16:45
问题 This question already has answers here : Convert row names into first column (7 answers) Closed 4 years ago . I have following data frame: RMSE A 0.03655830 B 0.24513014 C 0.02009853 D 0.02223135 I want to move column that has A,B,C,D to be the first column and add an index to the data.frame. 回答1: try this: df <- cbind(newColName = rownames(df), df) rownames(df) <- 1:nrow(df) hope this is what you meant, the result will be: newColName RMSE 1 A 0.03655830 2 B 0.24513014 3 C 0.02009853 4 D 0

Get column and row index pairs of Pandas DataFrame matching some criteria

╄→尐↘猪︶ㄣ 提交于 2021-02-08 04:59:50
问题 Suppose I have a Pandas DataFrame like following. These values are based on a distance matrix. A = pd.DataFrame([(1.0,0.8,0.6708203932499369,0.6761234037828132,0.7302967433402214), (0.8,1.0,0.6708203932499369,0.8451542547285166,0.9128709291752769), (0.6708203932499369,0.6708203932499369,1.0,0.5669467095138409,0.6123724356957946), (0.6761234037828132,0.8451542547285166,0.5669467095138409,1.0,0.9258200997725514), (0.7302967433402214,0.9128709291752769,0.6123724356957946,0.9258200997725514,1.0)