<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 This is an analysis of complaints data, munged here.
The fields are
Step1:  <h3>How many total complaints are there?</h3>
Step2:  <h3>How many complaints do not appear in the state's public database?</h3>
Step3:  <h3>How many complaints do appear in the state's public database?</h3>
Step4:  <h3>What percent of complaints are missing?</h3>
Step5:  <h3>How many complaints were labelled 'Exposed to potential harm' or 'No negative outcome?'</h3>
Step6:  <h3>Of all missing complaints, what percent are in the above two categories?</h3>
Step7:  <h3>What's the online/offline breakdown by outcome?</h3>
<i>This was used in graphics</i>
Step8:  <h3>How many offline complaints in the database were found to have "abuse," "neglect" or "exploitation?"</h3>
Step9:  "The state fined the facilities in hundreds of those cases."
<h3>In how many 'potential harm' cases were facilities fined?</h3>
<ASSISTANT_TASK:>
Python Code:
import pandas as pd
import numpy as np
from IPython.core.display import display, HTML
display(HTML("<style>.container { width:100% !important; }</style>"))
pd.set_option('display.max_colwidth', -1)
df = pd.read_csv('../../data/processed/complaints-3-29-scrape.csv')
Explanation: This is an analysis of complaints data, munged here.
The fields are:
1. <i>abuse_number:</i> A unique number assigned each complaint.
2. <i>facility_id:</i> A unique number to each facility building. Stays if ownership changes.
3. <i>facility_type:</i> NF: Nursing Facility; ALF: Assisted Living Facility; RCF: Residential Care Facility.
4. <i>facility_name:</i> Name of facility as of January 2017, when DHS provided the facility data to The Oregonian.
5. <i>abuse_type:</i> A – facility abuse; L – licensing. Note: This does not apply to nursing facilities. All their complaints are either blank in this field or licensing.
6. <i>fine:</i> Amount that state initialy fined the facility. Not necessarily amount of final fine.
7. <i>action_notes:</i> DHS determination of what general acts constituted the abuse or rule violation.
8. <i>incident_date:</i> Date the incident occured
9. <i>outcome:</i> A very brief description of the consequences of the abuse or rule violation to the resident
10. <i>outcome_notes:</i> A detailed description of what happened.
11. <i>year:</i> year incident occured
12. <i>online_fac_name:</i> If complaint is online, name listed for the facility
13. <i>public:</i> Whether or not complaint is online
14. <i>omg_outcome:</i> Field we created to group some similar outcomes.
End of explanation
df.count()[0]
Explanation: <h3>How many total complaints are there?</h3>
End of explanation
df[df['public']=='offline'].count()[0]
Explanation: <h3>How many complaints do not appear in the state's public database?</h3>
End of explanation
df[df['public']=='online'].count()[0]
Explanation: <h3>How many complaints do appear in the state's public database?</h3>
End of explanation
df[df['public']=='offline'].count()[0]/df.count()[0]*100
Explanation: <h3>What percent of complaints are missing?</h3>
End of explanation
df[(df['outcome']=='Exposed to Potential Harm') | (df['outcome']=='No Negative Outcome')].count()[0]
Explanation: <h3>How many complaints were labelled 'Exposed to potential harm' or 'No negative outcome?'</h3>
End of explanation
df[(df['outcome']=='Exposed to Potential Harm') |
   (df['outcome']=='No Negative Outcome')].count()[0]/df[df['public']=='offline'].count()[0]*100
Explanation: <h3>Of all missing complaints, what percent are in the above two categories?</h3>
End of explanation
totals = df.groupby(['omg_outcome','public']).count()['abuse_number'].unstack().reset_index()
totals.fillna(0, inplace = True)
totals['total'] = totals['online']+totals['offline']
totals['pct_offline'] = round(totals['offline']/totals['total']*100)
totals.sort_values('pct_offline',ascending=False)
Explanation: <h3>What's the online/offline breakdown by outcome?</h3>
<i>This was used in graphics</i>
End of explanation
df['outcome_notes'].fillna('', inplace = True)
df[(df['outcome_notes'].str.contains('constitute neglect|constitutes neglect|constitute abuse|constitutes abuse|constitutes exploitation|constitutes financial exploitation')) & (df['public']=='offline')].count()[0]
Explanation: <h3>How many offline complaints in the database were found to have "abuse," "neglect" or "exploitation?"</h3>
End of explanation
df[(df['omg_outcome']=='Potential harm') & (df['fine']>0) & (df['public']=='offline')].count()[0]
Explanation: "The state fined the facilities in hundreds of those cases."
<h3>In how many 'potential harm' cases were facilities fined?</h3>
End of explanation
<END_TASK>