-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpy39config.py
135 lines (115 loc) · 3.66 KB
/
py39config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# configs and utilities
try:
from loguru import logger
except ImportError:
from logging import getLogger
logger = getLogger(__name__)
logger.info('configuring ipython')
# pylab inline + other magic
from IPython import get_ipython
ipython = get_ipython()
ipython.magic('pylab inline')
ipython.magic('config InlineBackend.figure_format="retina"')
ipython.magic('load_ext autoreload')
ipython.magic('autoreload 2')
# cells can have multiple outputs
from IPython.core.interactiveshell import InteractiveShell
from IPython.display import display, HTML, display_html
InteractiveShell.ast_node_interactivity = "all"
import pandas as pd
pd.set_option('display.precision', 4)
pd.options.display.float_format = '{:.4f}'.format
pd.plotting.register_matplotlib_converters()
from pandas import DataFrame, Series, Timestamp
D, S, T = DataFrame, Series, Timestamp
import numpy as np
import scipy.stats as stats
import matplotlib.pyplot as plt
import seaborn as sns
from copy import copy
from pprint import pprint
from pathlib import Path
# grid_light_theme = {
# 'rc': {
# 'figure.figsize': (9, 5),
# 'grid.color': '#dddddd',
# 'axes.edgecolor': '#dddddd',
# 'legend.frameon': True,
# 'patch.force_edgecolor': True,
# },
# 'style': 'whitegrid',
# 'font_scale' : 1.25,
# 'color_codes': True,
# 'context': 'notebook'
# }
# ticks_light_theme = {
# 'rc': {
# 'figure.figsize': (9, 5),
# 'axes.spines.top': False,
# 'axes.spines.right': False,
# 'legend.frameon': False,
# 'patch.force_edgecolor': True,
# 'axes.titlepad': 30
# },
# 'style': 'ticks',
# 'font_scale' : 1.25,
# 'color_codes': True,
# 'context': 'notebook'
# }
# dark_theme_updates = {
# 'rc': {
# 'axes.facecolor': '#111111',
# 'figure.facecolor': '#111111',
# 'grid.color': '#6f6f6f',
# 'text.color': 'white',
# 'xtick.color': 'white',
# 'ytick.color': 'white',
# 'axes.edgecolor': '#6f6f6f',
# 'axes.labelcolor': 'white'
# }
# }
# grid_dark_theme = copy(grid_light_theme).update(dark_theme_updates)
# ticks_datk_theme = copy(ticks_light_theme).update(dark_theme_updates)
# #
# sns.set_theme(**grid_light_theme)
sns.set(rc={'figure.figsize': (9, 5)})
# setup hvplot and plotly
try:
import hvplot.pandas
import holoviews as hv
hvkw = dict(height=500, width=700, grid=True, legend='top')
except ImportError:
pass
try:
import plotly.express as px
px.defaults.template = "gridon"
px.defaults.width = 700
px.defaults.height = 500
# pd.options.plotting.backend = 'plotly'
except ImportError:
pass
try:
from ipydatagrid import DataGrid
except ImportError:
pass
def df_info(df):
display(df.info(verbose=True))
display(df.describe(include='all'))
display(df.sample(10))
def display_dfs_inline(dfs, captions=None, margin=5):
from functools import reduce
from IPython.display import display_html
captions = [''] * len(dfs) if captions is None else captions
stylers = [D(df).style.set_table_attributes(f'style="display:inline; margin:{margin}px;"').set_caption(c) for df, c in zip(dfs, captions)]
display_html(reduce(lambda x, y: x + y, (s._repr_html_() for s in stylers)), raw=True)
# reset any bultin we may have overidden
import builtins
for var in dir(builtins):
globals()[var] = getattr(builtins, var)
logger.info('done configuring ipython')
# # print setup info
# import os
# print('\nworking directory : ' + os.getcwd() + '\n')
# print(ipython.banner)
# import subprocess
# print(subprocess.run(['conda', 'info'], capture_output=True, shell=True).stdout.decode("utf-8"))