Q1. Create A File "People - TXT" With The Following Data:: Import As Import As Import As
Q1. Create A File "People - TXT" With The Following Data:: Import As Import As Import As
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
data = open('people.txt','r')
for line in data.readlines():
if line != '\n':
print(line)
2 child 3 married 0
34 child -7 married 3
df = pd.read_csv('people.txt',sep=" ",header=0)
df
ii) Create a ruleset E that contain rules to check for the following conditions:
for rules in E:
print(rules,'\n')
iii) Check whether ruleset E is violated by the data in the file people.txt.
rule_b = [0, 0, 0, 0]
for r in df.iterrows():
if r[1][0] < 0 or r[1][0] > 150:
rule_b[0] += 1
if r[1][0] <= r[1][4]:
rule_b[1] += 1
if r[1][3] not in ['single','married','widowed']:
rule_b[2] += 1
if (r[1][0] < 18 and r[1][1] != 'child') or (r[1][0] >= 18 and
r[1][0] <= 65 and r[1][1] != 'adult') or (r[1][0] > 65 and r[1][1] !=
'elderly'):
rule_b[3] += 1
if sum(rule_b) > 0:
print("Ruleset E is violated\n")
else:
print("Ruleset E is not violated\n")
Ruleset E is violated
Rule 1: 1
Rule 2: 1
Rule 3: 0
Rule 4: 1