logo
down
shadow

computing a value in a dataframe colum from another column, but only if a condition in a 3rd column is met


computing a value in a dataframe colum from another column, but only if a condition in a 3rd column is met

By : mcatalin
Date : October 16 2020, 03:08 PM
this will help When I do this: , Use loc to avoid chain indexing... and assignment on the chain index
code :
df.loc[mask, 'x'] =  1. / df.loc[mask, 'y']
df.x.values[mask] = 1. / df.y[mask]
df.loc[mask, 'x'] = 1. / df.y[mask]


Share : facebook icon twitter icon
Sum range in column with condition in another colum

Sum range in column with condition in another colum


By : MaiN
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , You can use the D column with something like =if(Ax="2"; Cx; 0) and then sum the D column. This doesn't use VBA and need a column but is very simple and just works.
How to use the sum values from a column in a multi-level indexed pandas dataframe as a condition for values in new colum

How to use the sum values from a column in a multi-level indexed pandas dataframe as a condition for values in new colum


By : user2597893
Date : March 29 2020, 07:55 AM
like below fixes the issue Problem is if use df.sum(level=0) it is same like df.groupby(level = 0).sum() - aggregation by first level of MultiIndex.
Solution is use GroupBy.transform for Series with same size like original DataFrame:
code :
df['Bet'] = np.where(df.groupby(level = 0)['Pot_Bet'].transform('sum') > 0.5*balance[-1], 
                     df['Pot_Bet'], 0)
print (df.groupby(level = 0)['Pot_Bet'].transform('sum'))
EVENT_ID   SELECTION_ID
112335580  6356576         18.859651
           2554439         18.859651
           2503211         18.859651
           6297034         18.859651
           4233251         18.859651
           2522967         18.859651
           5284417         18.859651
           7660920         18.859651
112335582  8112876         28.611078
           7546023         28.611078
           8175276         28.611078
           8145908         28.611078
           8175274         28.611078
           7300754         28.611078
           8065540         28.611078
           8175275         28.611078
           8106158         28.611078
           8086265         28.611078
           2291406         28.611078
           8065533         28.611078
           8125015         28.611078
Name: Pot_Bet, dtype: float64
print (df['Pot_Bet'].sum(level=0))
EVENT_ID
112335580    18.859651
112335582    28.611078
Name: Pot_Bet, dtype: float64

print (df.groupby(level = 0)['Pot_Bet'].sum())
EVENT_ID
112335580    18.859651
112335582    28.611078
Name: Pot_Bet, dtype: float64
Create a column in a spark dataframe from computing a value of the row with a whole column

Create a column in a spark dataframe from computing a value of the row with a whole column


By : user3218975
Date : March 29 2020, 07:55 AM
With these it helps You can't pass a whole column data to an UDF because the Spark engine is splitting the computation and the data across several servers/executors.
If you can adapt your algorithm to work on the executor local subset of the column values, you can use RDD.mapPartitions to execute a single function over a complete partition of data.
How to create new column in power bi using given string match condition in first column and get value from another colum

How to create new column in power bi using given string match condition in first column and get value from another colum


By : Michus001
Date : March 29 2020, 07:55 AM
I wish this helpful for you Go to the query designer Add Column > Custom Column and use the following expression:
code :
'Your Column3
=if Text.Contains([Col1], "A") = true then [Col2] else 0
'Your Column2
=if Text.Contains([Col1], "A") = false then [Col2] else 0
Filter a dataframe by a column if a condition is met in another colum with Dplyr R

Filter a dataframe by a column if a condition is met in another colum with Dplyr R


By : Sara_Designer
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , I haven't been able to find the answer to my question anywhere. I have an R dataframe, and I would like to filter by the value of a column if a condition is met in another column else the value shouldn't be filetered, and I would ideally do this using Dplyr. , You can use :
code :
library(dplyr)
dat %>% filter(type == "real" & value < 1 | type != "real")
subset(dat, type == "real" & value < 1 | type != "real")
Related Posts Related Posts :
  • How to equalize the size of two numpy arrays
  • Hive Server 2 error on python connect with hiveserver2
  • TypeError: argument 1 must have a "write" method
  • Python, read uart and post to MQTT, has extra spaces
  • test getting skipped in pytest
  • Python: from list to enumerated list to pass to lambda reduce function
  • f[1] raised exception TypeError: 'int' object is not subscriptable
  • how to make a random list in python3
  • Keeping Python from spacing after breaking a line when printing a List
  • Create a temporary table in python to join with a sql table
  • How to update a specific line in a file in python?
  • Google PubSub python client returning StatusCode.UNAVAILABLE
  • Error in regex substring match in a list in python
  • Pandas groupby() on one column and then sum on another
  • How to use multiple "or" in python code
  • spider = cls(*args, **kwargs) TypeError: __init__() got an unexpected keyword argument '_job'
  • Python, Django LDAP: detecting Authentication failed reasoning
  • Is it good to define a function in a function python
  • Zeep : Need to convert this sample soap request
  • How to render a template and send a file simultaneously with flask
  • Create new column in dataframe with match values from other dataframe
  • Group the values using one column and return the one having max value in other column using pandas dataframe
  • Python3 tkinter analog gauge
  • How to display all the data which is groupby "Cause" from 1981 to 1992 in python pandas?
  • Scrape content in json format - Python
  • How to replace pandas columns with the same name in to another dataframe?
  • Trying to build a proxy with aiohttp
  • Compound interest calculator loops
  • how to create a raw string when it's last character is a `\` in python
  • Scrapy - how can I split the data in this table?
  • Making post requests in python
  • How can I manipulate shapes (colors) in PowerPoint using Python and win32com.client?
  • Get sorted output for os.walk()
  • Pandas Mapping Column
  • How to remove border of microsoft word in text image in opencv with python?
  • why not always use map if its faster than the rest (list comprehension, loop (various variants))?
  • Trying to download a directory with requests
  • Django Django model “doesn't declare an explicit app_label” because of project's init.py file
  • Comparing 2 arrays using numpy and allocating values to a third array
  • How to do change the recieved SQL output format, in python
  • Python: how to write binary data to the stdout so that bash script can use process substitution?
  • How to combine two lists to get a new list of the shape as mentioned in description
  • Run-time Complexity for two algorithms (Big O notation calculation)
  • jupyter SSL: WRONG_VERSION_NUMBER
  • Import of csv data rows and columns when specyfing delimiter
  • Error in texting automated message in whatsapp using python
  • Why my model work ok with test data from train_test_split while doesn't with the new data?
  • Python Networkx: How to "redraw" graph after every iteration?
  • How to read a large json in pandas?
  • Protobuf Message Constructor
  • Keras: Concatenating metadata into a CNN
  • pyqtgraph get text of node and change color on MouseClick
  • how to handover *args to pathos' amap
  • Merge returns NaN except for first row
  • Seaborn graphing: Highlighting single data point in jointplot
  • ValueError: Metric 'cosine' not valid for algorithm 'ball_tree' when using sklearn TSNE
  • How to convert the strings in sublists into integer faster without forloop in python?
  • removing characters like '\u0152\xe6' from string
  • How do i get new line(row wise) output in SQL query using python
  • Saving an uploaded file to disk doesn't work in Flask
  • shadow
    Privacy Policy - Terms - Contact Us © soohba.com