Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

def calc_mean_mode(df, column_name)

### START FUNCTION
def calc_mean_mode(df, column_name):
    numeric = df.select_dtypes(include=['int64', 'float64']).columns
    non_numeric = df.select_dtypes(include=['object']).columns

    if column_name in numeric:
        return round(np.mean(df[column_name]), 2)

    elif column_name in non_numeric:
        return sorted(list(df[column_name].value_counts().index[df[column_name].value_counts() == df[column_name].value_counts().max()]))

    else:
        raise ValueError


### END FUNCTION
Comment

PREVIOUS NEXT
Code Example
Python :: how print array in python with clean dublication 
Python :: CVE-2018-10933 
Python :: pytorch studiogan 
Python :: éliminer le background image python 
Python :: python class destroying 
Python :: python minecraft server python gui 
Python :: How do I schedule an email to send at a certain time using cron and smtp, in python 
Python :: Python Print hour, minute, second and microsecond 
Python :: how to check if object is of file type in python3 
Python :: pandas excelfile 
Python :: Delete cell in jupiter notebook 
Python :: pygame pin to top 
Python :: add prefix to names in directory python 
Python :: sklearn grid search cross validation show progress 
Python :: python remove (string) 
Python :: python enumerate() 
Python :: create time array whith np.datetime64 
Python :: set index values pandas 
Python :: python list sort key lambda on equal other function 
Python :: Python try with else clause 
Python :: Python Difference between two timedelta objects 
Python :: Python update to beginning of dictionary 
Python :: how to capitalize words in python 
Python :: access icloud doc on jupyter notebook 
Python :: how to get last element of list in python 
Python :: python __add__ 
Python :: django count all objects 
Python :: how to redirect where requests library downloads file python 
Python :: migrate database in django 
Python :: figure in matplotlib 
ADD CONTENT
Topic
Content
Source link
Name
9+9 =