I have a table with some company information that we're trying to clean up. In the first column is a clean company name, but not necessarily the correct one. In the second column, there is the correct company name, but often not very clean / missing. Here is an example.
| Name | Info |
|---|---|
| Nike | Nike, a footwear manufacturer is headquartered in Oregon. |
| ASG Shoes | Reebok |
| Adidas | None |
We're working with this dataset in Pandas. We'd like to follow the rules below.
- If the Name column is equal to the left side of the Info column, keep the name column. We would like this to be dynamic with the length of column 1. For "Nike", it should check the first 4 letters of the Info column, for "ASG Shoes", it should check the first 9 characters.
- If rule 1 is false, use the Info column.
- If Info is None, use the Name column.
The output we seek is a 3rd column that is the output of these rules. I am hoping someone can help me with writing this code in an efficient manner. There's a lot going on here and I want to ensure I'm doing this properly. How can I achieve this output with the most efficient Python code possible?
| Name | Info | Clean |
|---|---|---|
| Nike | Nike, a footwear manufacturer is headquartered in Oregon. | Nike |
| ASG Shoes | Reebok | Reebok |
| Adidas | None | Adidas |