1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Python] How to pass a DataFrame column as an argument in a function?

Discussão em 'Python' iniciado por Stack, Setembro 11, 2024.

  1. Stack

    Stack Membro Participativo

    enter image description here Check the distribution of a specific value like the number of times the weather was exactly Cloudy in the given column. Feel free to check on other values. You can check it by calling the function clear with respective parameters.

    #Importing the modules
    import pandas as pd
    import numpy as np
    from scipy.stats import mode

    weather = pd.read_csv(path, sep = ",", delimiter = None)
    #code to check distribution of variable
    def clear(df,col,val):
    """ Check distribution of variable
    df,col,val
    This function accepts a dataframe,column(feature) and value which returns count of the value,
    containing the value counts of a variable(value_counts)

    Keyword arguments:
    df - Pandas dataframe
    col - Feature of the datagrame
    val - value of the feature

    Returns:
    value_counts - Value count of the feature
    """

    value_counts = df[(df.col == val)] # filtering dataframe
    print(len(value_counts))


    clear(weather,weather.Weather,'Cloudy') # calling function clear

    Continue reading...

Compartilhe esta Página