compute value based on condition of existing column dataframe

Solutions on MaxInterview for compute value based on condition of existing column dataframe by the best coders in the world

showing results for - "compute value based on condition of existing column dataframe"
Mariangel
23 Jun 2016
1# create a list of our conditions
2conditions = [
3    (df['likes_count'] <= 2),
4    (df['likes_count'] > 2) & (df['likes_count'] <= 9),
5    (df['likes_count'] > 9) & (df['likes_count'] <= 15),
6    (df['likes_count'] > 15)
7    ]
8
9# create a list of the values we want to assign for each condition
10values = ['tier_4', 'tier_3', 'tier_2', 'tier_1']
11
12# create a new column and use np.select to assign values to it using our lists as arguments
13df['tier'] = np.select(conditions, values)
14
15# display updated DataFrame
16df.head()
queries leading to this page
if else consition in pandasif in python dataframeif else conditiion in dataframefilter dataframe by equal column valueassign value to column based on condition pandasif condition in dfdataframe if else column conditionalthe importance of if else statement in python pandaspython if else dataframepandas elseifpandas python if else expressionif else dataframe in pythonpandas if by columndataframe if elseif else with condition in dataframe pythonpandas if else function formats on columnpandas set a value for column on conditionpandas conditional selection in listrevise a column in a pandas dataframe based on an if elseset value in column based on condition pandasdataframe if else columnif else for dataframe in pythonif statement python dataframeif else for data frame in pythonif else column pandashow to use if else in pandas dataframeusing if else condition on dataframe rowspd df if elseif else if with for python pandasnumpy if else dataframeapply if else pandascheck column value in datframe and modifiy the column data based on condition pandas pythonif else condition in pandas dataframepandas when if else columnpandas select values in column based on conditionif else python pandas columnif else condition dataframe pythonpandas dataframe instead of if conditionshow to check date values of a dataframe colums are equalpandas get value using condition of columnsconditional statement in python pandaspandas if else function formatsr if else as dataframepython pandas if statementpandas get column value by conditiondataframe if conditionif else pandas dataframeif else whil emerging data on pandasif else in pandasget value from dataframe pandas with conditionhow to use the if else statement in pandaspython dataframe condition where column equals valuepandas if else conditionif else in df applyif else in pandas dataframehow to set conditional statements in python pandasif do else do pandasshort if else in python pandasif condition pandas new columnhow to do if on a pandas dataframe if and else in dfupdate column value based on condition pandasif column value is equal to particular column find other column value in pandasupdating the values of column based on conditions of other columns pandaspandas when elsepandas condition ifif elif else pandas dataframeuse if else in dataframe pythonif condition on a pandas datafra 2ce 5celse panda pythonpandas if else columnpandas if and orif else in python dataframepandas add column conditionalpandas dataframe if elsecreate a new pandas dataframe column with if elsepandas get column value where conditionpython if dataframewhich column in dataframe where conditioncreate a new column in pandas using if statementcreate columns if statement pythonfill a column condition to a value in a column in another data frame in pythonelse if in pandasapplying an if condition under an existing dataframe columnif else statement in pandasdataframe column from if elsehow to apply if else in a dataframe pythondataframe if else column elifif else in python pandashow to use if statements in dataframe pythonpython pandas function if elseelse if python pandaspython pandas if else content in columnif else pandas dataframe columnupdate column value with condition in pandas dataframecreate column with condition pandas if loopapply to pandas column if value equals prior rowif else in pandas seriespandas if then elseif else pandaspandas if else elifhow o check if column1 values lies within 10 25 of another column value in pandasif statement dataframe pythonif and else condition in pandas udfhow to assign value to a column based on condition pandasstart next dataframe if pandas if else statementsif else in apply pandasshow dataframe column based on conditionif else in dataframe pythonpandas if else with columnspandas df if elsepandas value if elsehow to get column value where condition on another column pandasif 2felse pandasif else python pandasthe importance of if else for pandas dataframedataframe keep column depending on conditionelse if with for python pandasassign if else python dataframeif then dataframeif else python function apply pandas columnhow to apply if else in a dataframe cell in pythonif dataframe pythonpython if condition dataframe 27ifelse pandas serieshow to column in pandas using the if elsepandas conditional aggreagate depending on different column valuesif else selecting pandas dataframeif else in pandas columndataframe set value based on conditionpandas where elsepandas apply if elsehow to apply if else to data frame columnpython conditionally create new column in pandas dataframedataframe how to get column value from another column conditionalpandas conditional selectionhow to use if statement on a pandas dataframepandas if condition on columnpd df if else pythonif else in dfcreate pandas column with if elseif column value equals then pandasif elif and else for dataframeif else with column in dataframe pandasif else pandas on a columndf where column or condtionpandas where column value equals and another column value equalspandas if elsepandas dataframe add column using if statementbased on condition setting a value in dataframepandas column value if elsepandas if statementpandas if column value equals thenelse if pandaspandas if in columnnp where pandas conditions true falsecompute value based on condition of existing column dataframe