Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

pandas where

# replaces values with other where condition is False
DataFrame.where(cond, other=nan, inplace=False, axis=None, level=None, errors='raise', try_cast=False)

import pandas as pd 
df = pd.DataFrame({'values':[1,2,3,4]})

df.where(df['values'] % 2 == 0, -1) # output : [-1, 2, -3, 4]
Source by pandas.pydata.org #
 
PREVIOUS NEXT
Tagged: #pandas
ADD COMMENT
Topic
Name
1+4 =