I have a xlsx file (test.xlsx) and it looks like this:
| Name | Phone |
| ——– | ————– |
| John | yes |
| Jane | |
| Bob | |
| Cathy | yes |
| Will | |
What I want to do is to use pandas to read this file then if the Phone column is yes, I want to append ” – mobile” after “yes” then create a new xlsx file something like:
| Name | Phone | type |
| —— | ———— | ——– |
| John | yes | yes – mobile |
| Jane | | |
| Bob | | |
| Cathy | yes | yes – mobile |
| Will | | |
So, I create list to pet all the values in it. I tried like this:
df = pd.read_excel('test.xlsx')
l = df.get('Phone')
list = []
for value in df.index:
if value.isnull():
list.append(' ')
else:
list.append(value+' - mobile')
I want to add nothing or a space to list if the cell is empty but I don’t know how to check if it’s nan.
Any help will be appliciated. Thank you