0

I have a pretty basic problem that I'm having trouble explaining verbally, otherwise, I would just use an older answer. Would definitely appreciate being pointed in the right direction

Here's an example of what I need assistance with:

Project Name A Population A Project Name B Population B
0 Zebra Zebra 124
1 Horse Parrot 555
2 Parrot
3 Pufferfish Shark 442
4 Shark
5 Spider Cow 331
6 Pig Pig 953
7 Cow

How would I be able to insert the population data from Population B into Population A, given that the column in the row next to it in Project Name B matches Project Name A?

Sorry I'm having trouble explaining this!

I tried using the loc function in Pandas inside a loop, but that did not work other than for the first row of data.

clerno
  • 1
  • `df['Population A'] = df['Project Name A'].map(df.set_index('Project Name B')['Population B'])` – mozway May 01 '23 at 18:07
  • create two data frames from the databases then. Lets say PNA & PNB. Then do a merge in pandas "Merge = pd.merge(PNA, PNB, how = "inner", Left_on = "Project Name A", right_on = "Project Name B") . This should give you all the info you need to figure out what POP A should be. Could do something like if pop A is null then pop A = pop b or something of that nature. – Shell Shock May 01 '23 at 21:25

0 Answers0