Advertisement
Toxotsist

BD T1

Sep 9th, 2023 (edited)
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.20 KB | None | 0 0
  1. import itertools
  2. import math
  3. import operator
  4.  
  5. import numpy
  6. import pandas
  7. from sklearn.datasets import fetch_california_housing
  8.  
  9.  
  10. def p(tri: tuple, rec: tuple, circ: tuple):
  11.     s1 = tri[0] * (tri[1] / 2)
  12.     s2 = rec[0] * rec[1]
  13.     s3 = math.pi * (circ[0] ** 2)
  14.     return dict(zip(["triangle", "rectangle", "circle"], [s1, s2, s3]))
  15.  
  16.  
  17. # print(p((2, 3), (2, 3), (3, 2)))
  18.  
  19.  
  20. def do(a, b, op):
  21.     if op == "+":
  22.         return operator.add(a, b)
  23.     elif op == "-":
  24.         return operator.sub(a, b)
  25.     elif op == "*":
  26.         return operator.mul(a, b)
  27.     elif op == "/":
  28.         return operator.truediv(a, b)
  29.     elif op == "//":
  30.         return operator.mod(a, b)
  31.     elif op == 'abs':
  32.         return operator.abs(a, b)
  33.     elif op == "pow" or op == "**":
  34.         return operator.pow(a, b)
  35.  
  36.  
  37. # print(do(2, 3, "**"))
  38.  
  39.  
  40. def l():
  41.     a = list()
  42.     s = 0
  43.     while True:
  44.         k = int(input())
  45.         s += k
  46.         a.append(k)
  47.         if s == 0:
  48.             for i in a:
  49.                 s += i ** 2
  50.             print(s)
  51.             break
  52.  
  53.  
  54. # l()
  55.  
  56. def sc(n, al=0):
  57.     m = list()
  58.     for i in range(1, n):
  59.         al += i
  60.         if n >= al:
  61.             m.extend(itertools.repeat(i, i))
  62.     if len(m) < n:
  63.         m.append(max(m) + 1)
  64.         print(m)
  65.  
  66.     # sc(7)
  67.  
  68.  
  69. def cnt():
  70.     dct = dict()
  71.     a = [1, 2, 3, 4, 2, 1, 3, 4, 5, 6, 5, 4, 3, 2]
  72.     b = ['a', 'b', 'c', 'c', 'c', 'b', 'a', 'c', 'a', 'a', 'b', 'c', 'b', 'a']
  73.     dct = dict(zip(list(sorted(set(b))), itertools.repeat(0, len(b))))
  74.  
  75.     for i in range(len(b)):
  76.         bp = b.pop()
  77.         ap = a.pop()
  78.         match bp:
  79.             case "a":
  80.                 dct.update({'a': dct["a"] + ap})
  81.             case "b":
  82.                 dct.update({'b': dct["b"] + ap})
  83.             case "c":
  84.                 dct.update({'c': dct["c"] + ap})
  85.     print(dct)
  86.  
  87.  
  88. cnt()
  89.  
  90. def sk():
  91.     data = fetch_california_housing(as_frame=True)
  92.     df = data.frame
  93.     print(df.loc[(df['HouseAge'] > 50) & (df['Population'] > 2500)])
  94.     print(df.loc[df['MedHouseVal'].idxmax(), 'MedHouseVal'])
  95.     print(df.loc[df['MedHouseVal'].idxmin(), 'MedHouseVal'])
  96.     print(df.apply(numpy.average, result_type='expand'))
  97. sk()
  98.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement