简体   繁体   中英

Turn correlating rows values from positive to negative pandas dataframe

trying to write a script to process some invoices we to make things a bit easier. I have a data frame with 25 x columns and 725k x rows

very simply.

if the value in a column is negative then the value in the same row in column next to it is negative?

for i in solar['Usage']:
    if i == -i:
        i in solar['Value']
print('-'+ str(i))

i wrote this and it only turns the very bottom number of the entire data frame to a negative.

value  Usage
1      23
23    -43
23     34
34     23

if a value in usage is negative then the corresponding value in the same row has to be negative.

cheers for your help.

just starting out.

have looked everywhere.

Try this code:

solar['Usage'] = np.where(solar['value']<0, solar['Usage']*-1, solar['Usage'])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM