Creating new columns with conditions

Hey i have three columns (history, amount1 amount2)

History debit credit
Abc 1000 0
Xyz 0 1000
Az 200 0
Qw 0 200

I want to make new table in which i want

History Debit history credit
Abc 1000 Xyz 1000
Az 200 Qw 200

Its not always 0…it could be any number…
How to solve this?

If you post the code that you have (just a working model, not like 100s of lines) and I’m sure that someone will be able to help you.

I completely understand your point but im not able to build the logic…please help

There’s more than one way to do this, but I’m assuming that you’re a beginner and as such you’re learning the basics.

When planning a program, thing about what data you have, what you plan on doing with said data and what data types you have in order to accomplish the task.

This site covers the basics and much more, but there are others:

This is a start for you, just to get you going with one data type and how to access the data contained therein.

Apply what you know and learn what you don’t know in order to have a go at your project. Post back with your best effort and we’ll take it from there.

listName = ['Abc', 'Xyz', 'Az', 'Qw']

listDebit = [1000, 0, 200, 0]

listCredit = [0 ,1000, 0, 100]

Abc = str(listName[0]) + ':' + str(listDebit[0]) + ':' + str(listCredit[0])


Yess im a beginner and im learning and thank you for your help…but in the above query i just made a toy dataset but in real there are many different random values(90000 rows) in all columns so how can i do this

You’re welcome.

By learning the basics first; there are no short cuts if you want to learn how to code.

Yes yes you are right but this query stucked in my mind and im figuring out how to do

One of the cool things about code is called ‘looping’. This basically means that once you get code to do one thing correctly, you can loop it to do the same thing as many times as you need it to.