mardi 20 novembre 2018

Append values of a pandas data frame to a list by if condition

I've got a pandas df, which has one column with either positive or negative float values:

snapshot                        0 (column name)
2018-06-21 00:00:00        -60.18
2018-06-21 00:00:15         43.78
2018-06-21 00:00:30        -22.08

Now I want to append the positive values to a list that's called:

excessSupply=[]

and the negative values to:

excessLoad=[]

by

        for row in self.dfenergyBalance:

        if self.dfenergyBalance['0'] < 0:

            self.excessLoad.append(self.dfenergyBalance['0'])

        else:

            self.excessLoad.append(0)

(for excessSupply is the if condition self.dfenergyBalance > 0)

The outcome is a key error of the column name '0'

Aucun commentaire:

Enregistrer un commentaire