Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
I have a dataframe like this:
x,y,z 1,2,3 2,3,4 1,6,7
And I have a column like this:
a 4 5
Column a should be added when x = 1. So it should look like this:
x, y, z, a 1 2 3 4 2 3 4 NaN 1 6 7 5
How would I do this using pandas
Assign pandas object index will be one of the hidden key , so we should do assign by value only
pandas
object
index
df.loc[df['x'] == 1, 'a'] = col['a'].values
Add a comment
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.