Questions tagged [user-defined-functions]

A function provided by the user of a program or an environment most often for spreadsheet type applications or database applications. Use [custom-functions-excel] for Excel and [custom-function] for Google sheets. Specify a programming language tag as well: [google-apps-script], [javascript], [sql], [tsql], etc. as well as a tag for the application: [excel], [google-spreadsheet], [sql-server] etc.

In the context of a programming language or an environment, a User Defined Function (UDF) is a function that is created by a user to perform a specific task (as opposed to a function that is intrinsic to the environment, built into the programming language or environment).

Spreadsheet applications like Excel and Google Sheets calls these "custom functions".

Microsoft also uses the term User Defined Functions with . The tag may also be applicable. See What is the need for user-defined functions in SQL Server?

Use:

4875 questions
1
vote
1 answer

VBA UDF multi-cell reference

I am trying to create a UDF that takes the values from 4 selected cells and performs a function with it. However I don't know how to write the function to recognize the cell values. The way I have it currently written I need to input a value. Can…
user816845
1
vote
1 answer

Calculate the number of records whose values falls into each bin in SPARK

I have dataframe as below: ------+--------------+ | sid|first_term_gpa| +------+--------------+ |100170| 2.0| |100446| 3.8333| |100884| 2.0| |101055| 3.0| |101094| 3.7333| |101775| …
1
vote
1 answer

Class methods as Pyspark udf

I have the following code import numpy as np import pandas as pd class MyClass: def __init__(self, a: pd.Series): self.a = a def f(self, b: pd.Series): return np.exp(a) + b I also have a Pyspark dataframe with double…
1
vote
2 answers

Create a function that encodes strings to binary without using SciKit Learn - python 3

Creating a function that replaces all strings 't' and 'f' to 1s and 0s... this is where im at def binary_encoding(df): for col in df.columns: replace_map = {'t':1, 'f': 0,} df.columns.map(replace_map) -- not sure what to do here …
DropKick
  • 89
  • 1
  • 8
1
vote
1 answer

Sort the resulting DataFrame in pyspark using UDF

I am working in SPARK with diamonds dataframe. Data as below: +-----+-------+-----+-------+-----+-----+-----+----+----+----+ |carat| cut|color|clarity|depth|table|price| x| y| …
1
vote
3 answers

VBA User-defined functions in Office 365

Some MS Office versions place restrictions on user-defined functions. Specifically, UDFs cannot write to the excel worksheet outside the cells that call the function. My question: does this restriction apply in Office 365 as well?
1
vote
1 answer

pyspark cartesian product (crossJoin) with GroupedData

I have a pyspark dataframe +---+----+----+ |key|col1|col2| +---+----+----+ |a |5.4 | 1| |a |6.5 | 2| |b |7.5 | 3| |b |4.5 | 4| |c |6.4 | 1| +--------+----+ I want to do Cartesian product but not between each row, but between each…
1
vote
1 answer

How can I "group by" using a column without displaying it?

So I have an input file named "students.txt" which contains the following structure: id, first name, last name, date of birth. Here is the content of it: 111111 Harry Cover 28/01/1986 222222 John Doeuf 03/01/1996 333333 Jacques Selere…
cdaveau
  • 129
  • 1
  • 7
1
vote
1 answer

Passing values outside user's defined function in PARI GP

I want to write a function SWAP to swap 2 integers a and b in PARI. This function does not return any values but I want the variables outside the function to store the new values. I don't know how to fix this. This is my function: swap(a,b) = { t=a;…
1
vote
1 answer

Set precision of DecimalType returned by UDF

I have a DataFrame like this : // +---------+-----------+ // | myString| myDouble| // +---------+-----------+ // |AAA |2.0 | // |BBB |3.0 | // |CCC |1.0 | // +---------+-----------+ And i want to apply an UDF…
Marwan02
  • 45
  • 6
1
vote
1 answer

Get the row and column of the cell, where xlwings UDF was called?

I am using the xlwings library and I am creating custom UDF functions. @xw.func def hello(name): return f"Hello {name}!{os.getcwd()}" How can I get the row and the column of the cell where the function is called? To clarify, I want to access…
Borut Flis
  • 15,715
  • 30
  • 92
  • 119
1
vote
2 answers

Search Stored Procedures, Functions & Triggers for Keyword

I'm getting the error: Invalid column name 'Reserved' I'm not sure where in my database code this is, and have 100s of stored procedures, functions & triggers which I would have to manually look through to find this reference to an unknown…
Curtis
  • 101,612
  • 66
  • 270
  • 352
1
vote
1 answer

Is there a way to tag a Snowflake view as "safe" for result reuse?

Reading the Snowflake documentation for Using Persisted Query Results, one of the conditions that must be met for result reuse is the following: The query does not include user-defined functions (UDFs) or external functions. After some experiments…
danidiaz
  • 26,936
  • 4
  • 45
  • 95
1
vote
1 answer

In PySpark groupBy, how do I calculate execution time by group?

I am using PySpark for a university project, where I have large dataframes and I apply a PandasUDF, using groupBy. Basically the call looks like this: df.groupBy(col).apply(pandasUDF) I am using 10 cores in my Spark config…
user4514782
1
vote
2 answers

In a pandas pivot table, how do I define a function for a subset of data?

I'm working with a dataframe similar to this: Name Metric 1 Metric…
Sean R
  • 173
  • 1
  • 8
1 2 3
99
100