Questions tagged [apply]
A function to call another function with a list of arguments.
5,961
questions
0
votes
1
answer
30
views
Tailwind @apply in angular application .css file
And I am getting yellow line under the @apply. Though the css file is working correctly and it applies the styles within the components of html, still the yellow lines are under the @apply keyword. so ...
0
votes
0
answers
4
views
Is there a way to apply the macro code to all the rows in a column? Instead of typing out the code for each row
Hi I have a code as below, used for stock count:
`Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("C15")) Is Nothing Then
Application.EnableEvents = False
...
1
vote
2
answers
48
views
apply method didn't work as expected when DataFrame is empy
I've searched relevant posts before I create this post, but I didn't get what I want.
This is a simplified example shows that I use the apply method to create a new DataFrame named df_new based on the ...
0
votes
0
answers
66
views
Python: int() returning unexpected results
I have a scenario where I cannot use Python's inbuilt rounding functions so I have written a custom rounding function but it's not giving the expected result for a particular usecase. This is what I ...
1
vote
4
answers
72
views
Function applied to each element of a list and returns a list of list in R
For a list in R, I want to apply a function that accepts each element in each list and returns three numbers, which is the input value plus 1, 2, and 3. I want to create a list of list such that for ...
0
votes
2
answers
47
views
Using apply() family to repeate a plot() across columns
I would like to use the same plot() structure to generate several plots using y-values from different columns, with each column generating one plot.
I have tried this script:
multi.plot <- apply(x =...
0
votes
1
answer
35
views
Using Outer Apply to Compare 2 columns of one table that match values with 1 column in a different table
I'm new to APPLY statements in SQL and I'm trying to make a solution using an APPLY statement.
I have two tables:
Original ID
Target ID
SHAPE1
SHAPE2
SHAPE3
SHAPE4
Shape
Color
Num Sides
Size
...
0
votes
1
answer
41
views
Imputing missing values based on conditions from one df to another in pandas
I have a 2 dataframes, df1 and df2. I need to add values from df1 to df2. They both have different indexes- and df1 is calculated by groupby and average from some 3rd dataframe. I want to use apply ...
0
votes
3
answers
98
views
How to speed up pandas apply function with for loops? (Python)
I am working on texts for my project.
I want to replace words in my dataset texts by looking all words in dictionary.
My dictionary is like this;
replacement_dict ={'t1' : 'tebir', 't2':'teki', '...
2
votes
3
answers
40
views
Returning an extended matrix with apply
I have a matrix that that I am trying to use apply on, however my function takes a 10x1 matrix and then returns a 10x2 matrix (ie calaculates 2 values for each inout value). My overall dataframe is ...
-3
votes
1
answer
49
views
How to identify the links inside a DataFrame
I have a DataFrame of orders with a contract number
Orders
Contract
Order_1
Contract_1
Order_1
Contract_2
Order_2
Contract_1
Order_2
Contract_2
A contract can be linked to several orders.
An ...
1
vote
2
answers
70
views
How to iterate through Pandas and return first match found in sublist
I need a pandas apply function to iterate through sublists and return the first value found for each sublist.
I have a dataframe like this:
data = {'project_names': [['Datalabor', 'test', '...
0
votes
1
answer
11
views
How to create an apply function to calculate time difference between samples?
I am trying to calculate the average sampling frequency grouped by variable_units and sitename, and I want to use apply function instead of for loop for the calculations.
The first section of the code ...
0
votes
0
answers
42
views
Python Pandas DataFrame - .apply works not as expected, leads to wrong results
I have a pandas DataFrame in Python and want to apply a specific function pointwise on the entries of the first column.
For this purpose, I used the .apply-Method of pd.Series.
But with the function I ...
0
votes
0
answers
60
views
"Vue: Unknown at rule @apply" in IntelliJ IDEA despite official Tailwind plugin
I'm having issues using the @apply rule. It is marked as "Unknown" in my Vue files, despite having the official bundled Tailwind plugin enabled
These are my Plugin Settings, which I even ...
0
votes
2
answers
54
views
How do I efficiently remove the text in one column from another column in an R data frame?
I've tried both apply (apply & lapply) and foreach + doParallel, but I think I'm lacking complete understanding of these two concepts to be able to make them work.
Ultimately, I want to look at at ...
0
votes
3
answers
51
views
Rewrite a sequence of assignments with the apply functions in R
I was trying to simulate a sequence of measures of heights and weights of horses by breed, sampling the data from a list of breeds of horses available in the UK. I ended up using a very long code made ...
0
votes
1
answer
45
views
How to create a pandas function that tests if two string exist in multiple panda columns [duplicate]
I'm trying to write a function that scans through a set of columns and tests if two conditions exist across two different column rows. I'll then use this function and apply it my dataframe.
...
0
votes
1
answer
40
views
pd replace but based on other column
i have this dataframe
data = {'col_1': ['together', 'married', 'single', 'together'],
'kids': [1, 0, 0, 0],
'teen': [1, 1, 0, 0]
}
df = pd.DataFrame.from_dict(data)
df
Column A
Kids
Teen
Together
1
...
0
votes
0
answers
11
views
Taking advantage of JSON in list manipulation with R for aggregation
I have a JSON file such as :
{
"openmole-version" : "16.0-SNAPSHOT",
"execution-id" : "5b6cf33c-f219-4107-a81a-d8911b68d5df",
"script" : {
&...
1
vote
1
answer
58
views
type deducing only the arguments types for a variadic template
I am trying to apply a variadic template function to a tuple. I found following solution that works for C++14 (see https://stackoverflow.com/a/37100646/2712726).
#include <tuple>
template <...
1
vote
1
answer
58
views
Compute standar deviation in Pandas.DataFrame with custom mean value
I am facing the following problem:
I would like to be able to obtain the standard deviation for a group of values. The difficulty is in obtaining the std by applying the usual equation, but replacing ...
0
votes
2
answers
53
views
What and why following two with same apply() functionality differ in their results?
Objective is to convert each string to uppercase in Pandas dataframe (df).
Used following 3 approaches but not sure why 1st is NOT working ?
Please refer code snippet and 3 dataframes viz df1, df2, ...
0
votes
0
answers
25
views
Result type for groupby.apply() method depends on explicitly used index when dataframe-to-series function is used? [duplicate]
The groupby.apply() method has strange behavior when applied on dataframe-to-series function.
Having these test data
import pandas as pd
data = pd.DataFrame([['A', 2],
['B', 3], ...
0
votes
0
answers
104
views
How can I improve the runtime of row-wise operations in Polars?
We are looking to switch to Polars as our main data processing framework from DataFlow + mostly numpy. However some of transformation we apply atm are row-wise and can't be vectorised in neither numpy ...
0
votes
2
answers
73
views
Loop optimization in R
So... I'm trying to optimize for loppings in R.
My problem is: I have a multidimensional array (6 layers) and I want to get a matrix as answer.
For each cell position (i,j) I need to apply a function ...
0
votes
3
answers
81
views
Alternative to applying slicing of dataframe in pandas
I am trying to rank authors using an intersection of two metrics (where averaging wouldn't make sense) for each observation.
So far the only way I have done it was to apply a slice of the dataframe ...
0
votes
1
answer
43
views
Pandas apply casts None dtype to object or float depending on other outputs
I would like to control the output dtypes for apply on a row. foo and bar below have multiple outputs.
import pandas as pd
def foo(x):
return x['a'] * x['b'], None, x['a'] > x['b']
def bar(x):...
1
vote
2
answers
80
views
Function has 100-fold increase in duration for each 10-fold increase in input data
I wrote a simple function using sapply() to define the water year (Oct 1st - Sept 30th) for a vector of dates. It works well except that for every 10-fold increase in the length of vector supplied, ...
0
votes
1
answer
43
views
How to use group by with complex conditions without looping?
I have the following dataframe:
'Date': {0: pd.Timestamp('2022-10-10 00:00:00'), 1: pd.Timestamp('2022-10-10 00:00:00'), 2: pd.Timestamp('2022-10-10 00:00:00'), 3: pd.Timestamp('2022-10-10 00:00:00'), ...
1
vote
1
answer
46
views
How to apply a str_extract function to a range of table cells?
My ultimate goal is to plot a graph with the data source from a Wikipedia table.
I use R/selenium.
I've succeeded in modifying one of the cells:
library(RSelenium)
library(wdman)
library(netstat)
...
1
vote
1
answer
56
views
Applying function to Pandas Data frame and getting result as a new data frame
I have this code:
import yfinance as yF
import datetime
import pandas as pd
df = pd.DataFrame({'ID':['1', '2'], 'Ticker': ['AIN', 'TILE'], 'Company':['Albany International', 'Interface']})
def ...
0
votes
0
answers
31
views
How to use this function to apply to each row? [duplicate]
I have a dataframe with thousands of rows, a part of the dataframe is shown in the figure:
I defined two functions:
def zspread_solution(x):
FV = x[1]
COUPON_RATE = x[2]
T = x[3]
N = ...
0
votes
0
answers
35
views
Pandas category is set to anything? after using of apply, but for-loop works [duplicate]
I have a complex df, where I use categories. As example here a small example with leads to the same problem. You see, df and df_cpy look initially like this:
import pandas as pd
df = pd.DataFrame({&...
3
votes
1
answer
39
views
c-bind from a list of data tables without recycling and with using list names as part of column names
This is a follow-up question to a very similar issue where I already received great help here but I'm failing to modify the solution to the new requirements.
I have a list of data frames with ...
1
vote
2
answers
36
views
rbind 2 data frames by the elements in 2 columns, avoiding nested loops
I have two data frames like the following:
df1 <- data.frame(Marker1=c('+','+','+','-','-'), Marker2=c('+','+','+','+','-'), Marker3=c('+','-','+','-','+'),
Sample=c(1,1,2,3,3), ...
0
votes
1
answer
45
views
Applying two different functions to create new column
How can I use two different functions with different number of arguments and apply both to create new column in df. This works only for 1 function scenario depending on which apply method is ran last ...
1
vote
2
answers
107
views
Apparent Infinite Loop while trying to update Pandas Dataframe
I have a dataframe in which there is a field called section. Some rows have the value "Concurrent Opinion - x", where x is an index relative to the current document, which is another field ...
5
votes
1
answer
143
views
Under what circumstances is `vapply()` slower than `sapply()`?
The documentation for the *apply() functions states:
vapply is similar to sapply, but has a pre-specified type of return value, so it can be safer (and sometimes faster) to use. [Emphasis mine.]
It ...
0
votes
1
answer
51
views
Why does rolling.apply report an error? How should I modify the code
I have a dataframe like this:
time_node rate_node
0 30 1.67
1 60 1.82
2 90 2.13
3 180 2.53
4 270 2.68
5 360 2.71
I ...
2
votes
3
answers
54
views
pandas: Use apply to get columns with two highest values
I have a pandas dataframe and for each row would like to get the indices to the columns containing the two highest values
df = pd.DataFrame({"A": [10,20,30], "B": [20, 30, 10], &...
2
votes
2
answers
56
views
Pandas Series apply function that returns multiple rows and adds a second level to the index
I have a function that I apply to a Pandas Series elementwise, i.e. a map. That function returns multiple values (which I am returning as another Series at the moment, but can be a list instead). I ...
1
vote
2
answers
52
views
c-/r-bind from a list of data tables w/o recycling and w/ using list names as part of col names
there many post which shed some light on individual parts of my problem but I can't puzzle it together and need help. I'm trying to bind many data tables with varying row-count but identical column-...
0
votes
1
answer
25
views
assigning value for column based on whether or not text is present
I have a data frame:
Fruit
Color
apple
'is green'
apple
'big and Green'
apple
'is red'
banana
'yellow"
banana
'is yellow'
banana
'is small and yellow"
I want to make a third column, ...
2
votes
1
answer
35
views
Joining Function outputs with existing columns as new variable
I'm looking to do a conversion from datetime/pandas date's storage system to the one SAS uses for the purpose of joining with a variable.
Basically would like to go from this:
ID date
101 20-01-01
...
1
vote
0
answers
26
views
Find values in range with intervals from another dataframe
I have the following dataframe :
Slope_dist <- structure(list(Position = c(20050.1922349798, 20110.4724044041,
20191.8668595827, 20209.8075446083, 20244.6752987018, 20263.9822049159,
20281....
0
votes
1
answer
109
views
Flatten a numpy array and generate pandas columns based on array position
Apologies for cross posting on topics, but I'm looking to do a variation of something I did in R using python:
Counting unique characters between delimiters across a single Cell multiple times and ...
2
votes
2
answers
39
views
Obtain a vector of name concatenated with id from a list of data frames
I have a list of data frames like the following:
mylist=list()
mylist[['name1']]=data.frame(marker=LETTERS[1:3],values=1:3)
mylist[['name2']]=data.frame(marker=LETTERS[1:2],values=11:12)
that looks ...
0
votes
2
answers
52
views
Median from frequency table with `df.apply()`
I have a census frequency distribution and want to calculate the median please.
import pandas as pd
import math
import numpy as np
geo_code 1 2 3 4 5 6 7
0 ...
1
vote
2
answers
35
views
Python Pandas: Make two changes to df if a condition is met
I am new to python and trying to understand why my function is not working. Any guidance on why it is not working and how to fix would be very appreciated.
This is the df I am starting with:
import ...