I hope you are doing well. I have a question regarding a DataFrame in Python.
| Company | Job Title | Person Name |
|---|---|---|
| Apple | Founder | Steve Jobs |
| Apple | Co-Founder | Steve Wozniak |
| Microsoft | Founder | Bill Gates |
| Microsoft | Co-Founder | Paul Allen |
| Paypal | Co-Founder | Peter Thiel |
| Tesla | Board Member | Larry Ellison |
| Tesla | CFO | Zach Kirkhorn |
| Snapchat | Devan Fearman | Devan Fearman |
I would like to filter and create a new Dataframe which keeps only the rows based on the following conditions:
- if Founder then keep row
- if can't find Founder then Co-Founder
- if can't find Co-Founder then Board Member
- if can't find Board Member then Board Member CFO
Drop all other rows from the Dataframe. Note that I am allowed to have only 1 row per company.
Therefore I would like to have the following output below:
| Company | Job Title | Person Name |
|---|---|---|
| Apple | Founder | Steve Jobs |
| Microsoft | Founder | Bill Gates |
| Paypal | Co-Founder | Peter Thiel |
| Tesla | Board Member | Larry Ellison |
I am sure there is a way to do this using a loop function, however since I am very new to Python this is still very hard for me. I am open to using all libraries like pandas and numpy. Please explain your code as clearly as possible.
Hope to hear from you soon. Thank you and please let me know if I was not clear with my question.