Mar-04-2021, 04:01 PM
I want to write a three parameter function in Python. The output of the function should be data frame and it should square the given column. For example math_sq (df, column, value). How can I write this function?
How can I write a function with three parameters?
|
Mar-04-2021, 04:01 PM
I want to write a three parameter function in Python. The output of the function should be data frame and it should square the given column. For example math_sq (df, column, value). How can I write this function?
Mar-04-2021, 04:19 PM
What have you tried?
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link Create MCV example Debug small programs (Mar-04-2021, 04:19 PM)buran Wrote: What have you tried? I tried this below. But it didn't work. apply_math_sq(df,column,value): df[["col"]] = df[["col"]].pow(2) buran write Mar-04-2021, 05:17 PM:
Please, use proper tags when post code, traceback, output, etc. This time I have added tags for you. See BBcode help for more info.
Mar-04-2021, 05:23 PM
you miss
def . then there is problem how you access the column.import pandas as pd def apply_power_sq(df, column): df[column] = df[column].pow(2) df = pd.DataFrame({'spam': [0, 3, 4], 'eggs': [1, 2, 3]}) print(df) apply_power_sq(df, 'spam') print(df) Now, what is the purpose of value that you want to pass?
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link Create MCV example Debug small programs |
|
Possibly Related Threads… | |||||
Thread | Author | Replies | Views | Last Post | |
How to Write a function with Pandas? | SuperNinja3I3 | 4 | 2,281 |
Jul-03-2022, 02:19 PM Last Post: ndc85430 |
|
Write function to find decryptionkey | kotter | 3 | 3,055 |
Dec-11-2019, 07:04 PM Last Post: nilamo |
|
Writing a function that accepts two integer parameters (lines and cheers) | taydeal20 | 1 | 3,072 |
Feb-05-2018, 08:35 PM Last Post: nilamo |
|
how to write a function in python that solves an equation | samiraheen | 5 | 9,691 |
Sep-28-2017, 01:10 AM Last Post: Mekire |
|
Write a function sorting(L)? | MoIbrahim | 11 | 8,147 |
Apr-22-2017, 11:45 AM Last Post: idontreallywolf |
|
function to write the contents of a webpage into a new file | roadrage | 4 | 5,959 |
Dec-01-2016, 09:28 PM Last Post: snippsat |