-
Python - Get list span
摘要:def get_list_span(l: list): """ For list ['a', 'a', 'a', 'b', 'c', 'c', 'd', 'd', 'd', 'd'], its span list is [3, 0, 0, 1, 2, 0, 4, 0, 0, 0] . :param
阅读全文
-
Python - Get leaves count in a dictionary
摘要:def get_dict_leaves_count(dic): """ If value of a key is a list, count all items in the list as leaves. :param dic: :return: """ if len(dic) == 0: ret
阅读全文
-
Python - Convert sqlite3 rows to dictionary
摘要:def convert_sqlite_row_to_dict(row, n: int): """ Convert a single row of rows returned by a select query of sqlite3. :param row: :param n: The number
阅读全文
-
Python - Update dict in a cascade manner
摘要:def update_dict_cascade(dict_1, dict_2): """ Update dict_1 with dict_2 in a cascade manner. :param dict_1: The dict to be updated. :param dict_2: The
阅读全文
-
PyCharm - Disable reformatting on paste
-
PyCharm - Tab Size and Indent Size
-
Matplotlib - Figure Layout
摘要:The default is tight_layout. plt.subplots() plt.subplots(constrained_layout=True) constrained_layout can autoextend.
阅读全文
-
Matplotlib - Tick labels' rotation, size and alignment
摘要:for tick in ax2.get_xticklabels(): tick.set_rotation(45) tick.set_size(8) tick.set_ha('right')
阅读全文
-
Matplotlib - Line Graph and Bar Chart
摘要:def axes_show_y_value(axes, x_data, y_data): for x, y in zip(x_data, y_data): axes.annotate(str(y), # this is the text (x, y), # these are the coordin
阅读全文
-
Matplotlib - Embed graph in html web page
摘要:Python code: import base64from io import BytesIOdef fig_to_html(fig): """ Convert a matplotlib.Figure object to html image source :param fig: :return:
阅读全文
-
Pandas - Use multiindex
摘要:import pandas as pd df = pd.DataFrame([[2001, 'D', 2], [2004, 'T', 3], [2003, 'T', 5], [2001, 'T', 4], [2004, 'D', 7]], columns=['year', 'type', 'cnt'
阅读全文
-
Pandas - Get distinct values of a level of multiindex
摘要:print(df_year_month) print(' ') print(df_year_month.index) print(df_year_month.index.tolist()) print(' ') print(df_year_month.index.levels[0]) print(d
阅读全文
|