Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import itertools
- import math
- import operator
- import numpy
- import pandas
- from sklearn.datasets import fetch_california_housing
- def p(tri: tuple, rec: tuple, circ: tuple):
- s1 = tri[0] * (tri[1] / 2)
- s2 = rec[0] * rec[1]
- s3 = math.pi * (circ[0] ** 2)
- return dict(zip(["triangle", "rectangle", "circle"], [s1, s2, s3]))
- # print(p((2, 3), (2, 3), (3, 2)))
- def do(a, b, op):
- if op == "+":
- return operator.add(a, b)
- elif op == "-":
- return operator.sub(a, b)
- elif op == "*":
- return operator.mul(a, b)
- elif op == "/":
- return operator.truediv(a, b)
- elif op == "//":
- return operator.mod(a, b)
- elif op == 'abs':
- return operator.abs(a, b)
- elif op == "pow" or op == "**":
- return operator.pow(a, b)
- # print(do(2, 3, "**"))
- def l():
- a = list()
- s = 0
- while True:
- k = int(input())
- s += k
- a.append(k)
- if s == 0:
- for i in a:
- s += i ** 2
- print(s)
- break
- # l()
- def sc(n, al=0):
- m = list()
- for i in range(1, n):
- al += i
- if n >= al:
- m.extend(itertools.repeat(i, i))
- if len(m) < n:
- m.append(max(m) + 1)
- print(m)
- # sc(7)
- def cnt():
- dct = dict()
- a = [1, 2, 3, 4, 2, 1, 3, 4, 5, 6, 5, 4, 3, 2]
- b = ['a', 'b', 'c', 'c', 'c', 'b', 'a', 'c', 'a', 'a', 'b', 'c', 'b', 'a']
- dct = dict(zip(list(sorted(set(b))), itertools.repeat(0, len(b))))
- for i in range(len(b)):
- bp = b.pop()
- ap = a.pop()
- match bp:
- case "a":
- dct.update({'a': dct["a"] + ap})
- case "b":
- dct.update({'b': dct["b"] + ap})
- case "c":
- dct.update({'c': dct["c"] + ap})
- print(dct)
- cnt()
- def sk():
- data = fetch_california_housing(as_frame=True)
- df = data.frame
- print(df.loc[(df['HouseAge'] > 50) & (df['Population'] > 2500)])
- print(df.loc[df['MedHouseVal'].idxmax(), 'MedHouseVal'])
- print(df.loc[df['MedHouseVal'].idxmin(), 'MedHouseVal'])
- print(df.apply(numpy.average, result_type='expand'))
- sk()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement