apply Questions

13

Solved

I have a pandas DataFrame, df_test. It contains a column 'size' which represents size in bytes. I've calculated KB, MB, and GB using the following code: df_test = pd.DataFrame([ {'dir': '/Users/u...
Leprosarium asked 10/5, 2014 at 21:27

7

Solved

I tried this: // mod.js var a = 1; this.b = 2; exports.c = 3; // test.js var mod = require('./mod.js'); console.log(mod.a); // undefined console.log(mod.b); // 2 console.log(mod.c); // 3, so this...
Formication asked 28/2, 2012 at 2:56

7

Solved

I want to apply a function with arguments to a series in python pandas: x = my_series.apply(my_function, more_arguments_1) y = my_series.apply(my_function, more_arguments_2) ... The documentatio...
Clot asked 29/8, 2012 at 16:46

3

Solved

I have a Python Pandas dataframe df: d = [['hello', 1, 'GOOD', 'long.kw'], [1.2, 'chipotle', np.nan, 'bingo'], ['various', np.nan, 3000, 123.456]] t = pd.DataFrame(data=d, columns=['A','B','C','D...
Nickynico asked 10/5, 2017 at 16:24

3

Solved

I want to apply a function to a rolling window. All the answers I saw here are focused on applying to a single row / column, but I would like to apply my function to the entire window. Here is a si...
Illlooking asked 5/5, 2019 at 9:33

2

Solved

I have 2 dataframes: The main one df Another dataframe tmp which describes columns types of df and the New_format on which columns should be converted Here is a reproducible example: df <- dat...
Saxton asked 24/5, 2022 at 21:41

5

Solved

I would like to use Pandas df.apply but only for certain rows As an example, I want to do something like this, but my actual issue is a little more complicated: import pandas as pd import math z ...
Hach asked 18/11, 2015 at 0:43

2

I want to apply a patch to a file in the current directory. The path in the patch file says just a/FILETOPATCH.something b/FILETOPATCH.something. If I use this with git apply it isn't working. The ...
Conative asked 4/8, 2011 at 15:3

3

Solved

I have a data.frame where some cells contain strings of comma separate values: d <- data.frame(a=c(1:3), b=c("name1, name2, name3", "name4", "name5, name6"), c=c("name7","name8, name9", "na...
Adductor asked 7/10, 2016 at 17:26

5

Solved

I tried to perform independent t-test for many columns of a dataframe. For example, i created a data frame set seed(333) a <- rnorm(20, 10, 1) b <- rnorm(20, 15, 2) c <- rnorm(20, 20, 3) ...
Dominate asked 21/2, 2018 at 14:8

7

Solved

I have a dataframe (in Python 2.7, pandas 0.15.0): df= A B C 0 NaN 11 NaN 1 two NaN ['foo', 'bar'] 2 three 33 NaN I want to apply a simple function for rows that does not contain NULL values in...
Endoderm asked 28/10, 2014 at 17:15

2

Solved

I have a pandas dataframe 'df' with two columns 'A' and 'B', I have a function with two arguments def myfunction(B, A): # do something here to get the result return result and I would like to ...
Cnossus asked 2/10, 2016 at 6:19

1

I want to pass each row of a Polars DataFrame into a custom function. def my_complicated_function(row): # ... return result df = pl.DataFrame({ "foo": [1, 2, 3], "bar"...
Holguin asked 29/3, 2022 at 8:42

7

Solved

Suppose I have a n by 2 matrix and a function that takes a 2-vector as one of its arguments. I would like to apply the function to each row of the matrix and get a n-vector. How to do this in R? F...
Philcox asked 21/11, 2010 at 3:59

8

Solved

I'm trying to get the min/max for each column in a large data frame, as part of getting to know my data. My first try was: apply(t,2,max,na.rm=1) It treats everything as a character vector, beca...
Matchless asked 5/9, 2011 at 2:6

3

Solved

I often have the problem that R converts my one column data frames into character vectors, which I solve by using the drop=FALSE option. However, there are some instances where I do not know how to...
Yl asked 17/3, 2022 at 9:24

3

Solved

I have the following data frame my_df: Person event time --------------------------------- John A 2017-10-11 John B 2017-10-12 John C 2017-10-14 John D 2017-10-15 Ann X 2017-09-01 Ann Y 2017-09-02...
Petua asked 23/10, 2017 at 17:35

6

Solved

I want to use the apply function on a dataframe, but only apply the function to the last 5 columns. B<- by(wifi,(wifi$Room),FUN=function(y){apply(y, 2, A)}) This applies A to all the columns ...
Swathe asked 29/8, 2013 at 5:48

1

I am trying to move uncommited changes from a local git repository to another local repository. On repo 1 I create a patch like this: git diff > my_patch.patch Inspecting the patch: more my_pat...
Koren asked 29/4, 2020 at 8:10

2

Solved

I have a vector of values: y=c(2,3,4,4,3,2,1,1) And a list of vectors of positions: l=list(c(1,2),c(2,3),c(3,4),c(4,5),c(5,6),c(6,7),c(7,8),c(8,1)) I'd like to replace the value of y by NAs (or o...
Chouinard asked 24/12, 2021 at 17:11

4

Solved

Let's say I've got a dataframe with multiple columns, some of which I want to transform. The column names define what transformation needs to be used. library(tidyverse) set.seed(42) df <- data....
Slambang asked 19/12, 2021 at 9:58

5

Solved

I have this example matrix and I want to change the entries of the matrix with "YES" or "NO" based on a conditional if statement. a<-c(5,1,0,3,2,0.6,1.6,7,9,0) b<-c(11,0,1...
Thoron asked 15/8, 2021 at 11:16

1

Solved

I want to apply a function on groups of a data frame and get the function output as a new column. Here is the function that I wrote: def get_centroids(sample): # Ideally, re = complex_function(s...
Paranoiac asked 28/7, 2021 at 6:15

5

Solved

I have a large data frame, df, containing 4 columns: id period ret_1m mkt_ret_1m 131146 CAN00WG0 199609 -0.1538 0.047104 133530 CAN00WG0 199610 -0.0455 -0.014143 135913 CAN00WG0 199611 0.0000 0.0...
Defend asked 15/1, 2016 at 1:36

6

Solved

I need to convert many columns that are numeric to factor type. An example table: df <- data.frame(A=1:10, B=2:11, C=3:12) I tried with apply: cols<-c('A', 'B') df[,cols]<-apply(df[,co...
Livvie asked 7/12, 2015 at 0:5

© 2022 - 2024 — McMap. All rights reserved.