>>> import random
>>>
>>> vars = ['yes', 'no']
>>> random.choices(vars, weights=[0.9, 0.1])
['yes']
>>> random.choices(vars, weights=[0.9, 0.1])
['yes']
>>> random.choices(vars, weights=[0.9, 0.1])
['no']
>>> random.choices(vars, weights=[0.9, 0.1])
['yes']
>>> random.choices(vars, weights=[0.9, 0.1])
['yes']
>>>
>>> import pandas as pd
>>>
>>> df1 = pd.DataFrame({'item': [1, 2, 3, 4], 'val1': [213, 31, 12, 2132], 'val2': [54, 322, 23, 23]})
>>> df2 = pd.DataFrame({'item': [1, 2, 3, 4], 'val1': [213, 31, 12, 2132], 'val2': [32112, 132412, 1354112, 123412]})
>>>
>>> df1 = df1[['item', 'val1']]
>>> df2 = df2[['item', 'val2']]
>>>
>>> df = df1.merge(df2, on='item', how='inner')
>>> df
item val1 val2
0 1 213 32112
1 2 31 132412
2 3 12 1354112
3 4 2132 123412
>>>
from collections import defaultdict
from pprint import pprint
strange_lists = [['Егор', '1', 'Вася', '0'], ['Петя', '4', 'Вася', '5'], ['Егор', '2', 'Петя', '2'], ['Никита', '4', 'Андрей', '4']]
counter = defaultdict(int)
for strange_list in strange_lists:
for i in strange_list:
try:
int(i)
continue
except ValueError:
pass
counter[i] += 1
pprint(counter)
# defaultdict(<class 'int'>,
# {'Андрей': 1,
# 'Вася': 2,
# 'Егор': 2,
# 'Никита': 1,
# 'Петя': 2})