In [13]:
import numpy as np
# `numpy.random` uses its own PRNG.
np.random.seed(444)
np.set_printoptions(precision=3)
df = np.random.laplace(loc=15, scale=3, size=500)
df[:5]
np.array([18.406, 18.087, 16.004, 16.221, 7.358])
hist, bin_edges = np.histogram(df)
In [14]:
print(hist, bin_edges)
In [15]:
df = pd.Series(data).value_counts()
In [17]:
import pandas as pd
df = pd.DataFrame({'c':[1,1,2,2,3,3],'L0':['a','a','b','c','d','e'],'L1':['a','b','c','e','f','e']})
In [20]:
df_1 = pd.crosstab(df.c, df.L0)
print(df_1)
# print(df)
In [22]:
a = [{'count': 2, 'value': '10'}, {'count': 2, 'value': '7'}, {'count': 2, 'value': '8'}, {'count': 1, 'value': None}]
def deep_sort(obj):
"""
Recursively sort list or dict nested lists
"""
if isinstance(obj, dict):
_sorted = {}
for key in sorted(obj):
_sorted[key] = deep_sort(obj[key])
elif isinstance(obj, list):
new_list = []
for val in obj:
new_list.append(deep_sort(val))
print(new_list)
_sorted = sorted(new_list)
else:
_sorted = obj
return _sorted
deep_sort(a)
In [23]:
sorted([{'count': 2, 'value': '10'}, {'count': 2, 'value': '7'}, {'count': 2, 'value': '8'}, {'count': 1, 'value': None}])
In [ ]: