0

Problem example

I am trying to accomplish a task in python. I have data coming in everyday. There is a column called "PIA_Status". PIA_Status for an Application ID can be "Not Started", "Started" and "Completed". Whenever PIA Status = "Completed", the Task Status column should have closed for "Not Started" and "Started". I am trying to achieve this programmatically using python and not sure how to do this. Any help is much appreciated

  • you must provide a fully [reproducible example](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples) and the matching expected output – mozway Sep 23 '22 at 09:40
  • Please provide enough code so others can better understand or reproduce the problem. – Community Sep 23 '22 at 11:11

1 Answers1

0

if i understood what you want, here's somthing that you can work around with.

import pandas as pd

data = pd.read_excel('data.xlsx', sheet_name='Sheet1')
data.loc[data['pia_status'] != 'completed', 'Task Status'] = 'Closed' 
# print(data)
pd.DataFrame(data).to_excel('data.xlsx', sheet_name='Sheet1', index=False)

here's a more readable solution for beginners with a for each and an if statement:

import pandas as pd

data = pd.read_excel('data.xlsx', sheet_name='Sheet1')

for i in range(len(data)):
    if data['pia_status'][i] != 'completed':
        data['Task Status'][i] = 'Closed'
    else:
        data['Task Status'][i] = ''
# print(data)
data.to_excel('data.xlsx', sheet_name='Sheet1', index=False)
Hannon qaoud
  • 785
  • 2
  • 21