0
I have a pandas dataframe with five rows 3 three columns. I want to create a function where my code returns columns where the last row is larger than the first row. In the example of my code I want it to generate me a list with the column name 'Temp01'. I got in the way of creating if/Else to check the columns whose last row is larger than the first. Below follows my code:
#Importa as Bibliotecas Pandas e Numpy
import pandas as pd
#Cria do Dataframe
df0 = pd.DataFrame({'Temp01':[10,20,30,40,15],'Temp02':[50,60,70,70,45],'Temp03':[80,90,100,100,75]})
#Separa Colunas cuja ultima linha seja maior que a primeira
alta =[]#Tendência de Alta
for column in df0.columns:
if df0.column[-1]> df0.column[0]:
text = column
alta.append(text)
else:
pass
print(alta)
Oops. Thanks for your help. But the result returned me the difference...but I want him to return me the columns ("Temp0", "Temp1", "Temp2") whose last row is greater q the first. But your code has helped me enough. Thank you.
– Rodrigo Ferraz
Oops! good that helped. I got caught by the post title "Calculating difference between first and last line on a dataframe pandas"
– Paulo Marques