Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
295 views
in Technique[技术] by (71.8m points)

python - 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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Try this code:

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...