list with values greater than those reported by the user

Asked

Viewed 39 times

-1

I need a program that prints a list with values greater than the one informed by the user, and these values that need to be printed by the list are in a function already defined. My code:

import pandas as pd

dados = pd.read_csv('./DadosClimaticos2018Londrina.csv', sep = ';', parse_dates = ['Data'])
dados['Mes'] = pd.DatetimeIndex(dados['Data'], yearfirst = True).month

# FUNÇÕES
def um(temp):
    return pd.DataFrame(temp.groupby('Mes')['Temperatura'].mean()).reset_index()

listaTM = []
tmmin = float(input('Digite a temperatura media minima: '))  
listaTM.append(tmmin)
print(listaTM) 

1 answer

0

Importing the package:

import pandas as pd

Loading the data and creating a new column:

dados = dados = pd.read_csv('./DadosClimaticos2018Londrina.csv', sep = ';', parse_dates = ['Data']) 
dados['Mes'] = pd.DatetimeIndex(dados['Data'], yearfirst = True).month

Function that returns temperature averages per month:

def um(temp): 
    return pd.DataFrame(temp.groupby('Mes')['Temperatura'].mean()).reset_index()

Receiving the minimum value from the user:

tmmin = float(input('Digite a temperatura media minima: '))

Function that returns temperatures higher than the filter:

def um_filtro(temp, tem_min):
    temp1 = um(temp)
    return temp1[temp1['Temperatura'] > tem_min]

We take advantage of the medium function and call it within the filter function.


Calling the function and passing the values:

um_filtro(dados,tmmin)

Exit:

    Mes     Temperatura
0     1     24.763441
2     3     24.776344
3     4     24.008889
10   11     24.653333
11   12     26.073118

Browser other questions tagged

You are not signed in. Login or sign up in order to post.