CODE FOR ASSIGNMENTS 1 AND 2 BELOW! import pandas as pd ASSIGNMENT 1: # perform the set difference of the two tables diff = pd.merge(A, B, on='Country', how='outer', indicator=True) diff = diff[diff['_merge'] == 'left_only'].drop('_merge', axis=1) # output the set difference table and the cardinality of the operation print(diff) print(f"Cardinality of A-B: {len(diff)}") import pandas as pd # perform the intersection of the two tables intersection = pd.merge(A, B, on='Founded') # output the intersection table and the cardinality of the operation print(intersection) print(f"Cardinality of AB: {len(intersection)}") import pandas as pd # filter the rows based on the condition C = A[A['Country'] == 'United States of America'] # write the filtered table to a new CSV file C.to_csv('organizations-C.csv', index=False) # output the filtered table and the cardinality of the operation print(C) print(f"Cardinality of the condition: {len(C)}") import pandas as pd # perform the union of the two tables union = pd.concat([A, B], axis=1) # output the union table and the cardinality of the operation print(union) print(f"Cardinality of AB: {len(union)}") ASSIGNMENT 2: import random # Generate two sets of five unique random integers between 11 and 99 X = set(random.sample(range(11, 100), 5)) Y = set(random.sample(range(11, 100), 5)) # Compute the product of X and Y product = set(x * y for x in X for y in Y) # Compute the absolute value of the product abs_product = abs(sum(product)) print("X:", X) print("Y:", Y) print("X*Y:", product) print("|X*Y|:", abs_product) def fibonacci(n): if n <= 1: return n else: return fibonacci(n-1) + fibonacci(n-2) #generate the sequence of fibonacci numbers starting with f5 to f10 for i in range(5, 11): print("f" + str(i) + ":", fibonacci(i)) import math def sinc(x): if x == 0: return 1 else: return math.sin(x) / x #to determine if the function is one-to-one, we can take the derivative of 'sinc(x)': def d_sinc(x): if x == 0: return 0 else: return (x * math.cos(x) - math.sin(x)) / (x**2) is_one_to_one = True for x in range(-5, 6): if d_sinc(x) == 0: is_one_to_one = False break elif d_sinc(x) < 0: is_one_to_one = False break if is_one_to_one: print("sinc(x) is one-to-one on [-5, 5]") else: print("sinc(x) is not one-to-one on [-5, 5]") #to determine if the function is increasing is_increasing = True for x in range(-5, 6): if d_sinc(x) < 0: is_increasing = False break if is_increasing: print("sinc(x) is increasing on [-5, 5]") else: print("sinc(x) is not increasing on [-5, 5]") #to determine if the function is onto sinc_values = set() for x in range(-5, 6): sinc_values.add(sinc(x)) if len(sinc_values) == 11: print("sinc(x) is onto on [-5, 5]") else: print("sinc(x) is not onto on [-5, 5]") #to determine if the is bijective is_one_to_one = True is_increasing = True sinc_values = set() for x in range(-5, 6): if d_sinc(x) == 0: print 1. Verify the programs you wrote for Assignment01 (the one with the files) \& Assignment02 and calculate thei.
CODE FOR ASSIGNMENTS 1 AND 2 BELOW! import pandas as pd ASSIGNMENT 1: # perform the set difference of the two tables diff = pd.merge(A, B, on='Country', how='outer', indicator=True) diff = diff[diff['_merge'] == 'left_only'].drop('_merge', axis=1) # output the set difference table and the cardinality of the operation print(diff) print(f"Cardinality of A-B: {len(diff)}") import pandas as pd # perform the intersection of the two tables intersection = pd.merge(A, B, on='Founded') # output the intersection table and the cardinality of the operation print(intersection) print(f"Cardinality of AB: {len(intersection)}") import pandas as pd # filter the rows based on the condition C = A[A['Country'] == 'United States of America'] # write the filtered table to a new CSV file C.to_csv('organizations-C.csv', index=False) # output the filtered table and the cardinality of the operation print(C) print(f"Cardinality of the condition: {len(C)}") import pandas as pd # perform the union of the two tables union = pd.concat([A, B], axis=1) # output the union table and the cardinality of the operation print(union) print(f"Cardinality of AB: {len(union)}") ASSIGNMENT 2: import random # Generate two sets of five unique random integers between 11 and 99 X = set(random.sample(range(11, 100), 5)) Y = set(random.sample(range(11, 100), 5)) # Compute the product of X and Y product = set(x * y for x in X for y in Y) # Compute the absolute value of the product abs_product = abs(sum(product)) print("X:", X) print("Y:", Y) print("X*Y:", product) print("|X*Y|:", abs_product) def fibonacci(n): if n <= 1: return n else: return fibonacci(n-1) + fibonacci(n-2) #generate the sequence of fibonacci numbers starting with f5 to f10 for i in range(5, 11): print("f" + str(i) + ":", fibonacci(i)) import math def sinc(x): if x == 0: return 1 else: return math.sin(x) / x #to determine if the function is one-to-one, we can take the derivative of 'sinc(x)': def d_sinc(x): if x == 0: return 0 else: return (x * math.cos(x) - math.sin(x)) / (x**2) is_one_to_one = True for x in range(-5, 6): if d_sinc(x) == 0: is_one_to_one = False break elif d_sinc(x) < 0: is_one_to_one = False break if is_one_to_one: print("sinc(x) is one-to-one on [-5, 5]") else: print("sinc(x) is not one-to-one on [-5, 5]") #to determine if the function is increasing is_increasing = True for x in range(-5, 6): if d_sinc(x) < 0: is_increasing = False break if is_increasing: print("sinc(x) is increasing on [-5, 5]") else: print("sinc(x) is not increasing on [-5, 5]") #to determine if the function is onto sinc_values = set() for x in range(-5, 6): sinc_values.add(sinc(x)) if len(sinc_values) == 11: print("sinc(x) is onto on [-5, 5]") else: print("sinc(x) is not onto on [-5, 5]") #to determine if the is bijective is_one_to_one = True is_increasing = True sinc_values = set() for x in range(-5, 6): if d_sinc(x) == 0: print 1. Verify the programs you wrote for Assignment01 (the one with the files) \& Assignment02 and calculate thei.