Skip to content

Instantly share code, notes, and snippets.

View izikeros's full-sized avatar

Krystian Safjan izikeros

View GitHub Profile
@izikeros
izikeros / directed_graph_with_edge_labels.dot
Last active March 14, 2024 09:52
[Graphviz example] directed graph with labels on the edges #graphviz
# see: https://stackoverflow.com/a/1806873/3247880
digraph G {
a -> b [ label=" a to b" ];
b -> c [ label=" another label"];
}
@izikeros
izikeros / .flake8
Last active March 15, 2024 20:04
[flake8 configuration] Configuration for Flake8 with plugins: flake8-bugbear, flake8-commas, flake8-docstrings, flake8-print, flake8-pytest, flake8-pytest-mark #qa #python #project #configuration
; Configuration for Flake8 with plugins:
; flake8-bugbear,
; flake8-commas,
; flake8-docstrings,
; flake8-print,
; flake8-pytest,
; flake8-pytest-mark
; flake8-import-order
[flake8]
@izikeros
izikeros / matplotlib_styling.py
Last active March 14, 2024 09:54
[matplotlib styling] Set style to have beautiful plots with matplotlib. #matplotlib #python
from matplotlib import pyplot as plt
"""If used in Jupyter notebook, this can be embedded by adding cell:
%%bash
if [ ! -e matplotlib_styling.py ]; then
wget https://gist.githubusercontent.com/izikeros/457a99d950310da8166050a13f4043cb/raw/4334d77bdaad867003926e7cf87ffbec7131528d/matplotlib_styling.py
fi
"""
@izikeros
izikeros / start.py
Last active March 15, 2024 20:11 — forked from WillKoehrsen/start.py
[notebook pre-load and pre-config] Script with commands that will be executed upon notebook initialization #notebook #jupyter
"""
If you often use interactive IPython sessions or Jupyter Notebooks and you’re getting tired of importing the same libraries over and over, try this:
Navigate to ~/.ipython/profile_default
Create a folder called startup if it’s not already there
Add a new Python file called start.py
Put your favorite imports in this file
Launch IPython or a Jupyter Notebook and your favorite libraries will be automatically loaded every time!
author: Will Koehrsen
@izikeros
izikeros / pandas_progressbar.py
Last active March 15, 2024 19:59
[DataFrame processing progress bar] Display progress bar while processing pandas dataframe #pandas
# from:
# https://stackoverflow.com/a/34365537/3247880
# see internals:
# https://github.com/tqdm/tqdm/blob/master/examples/pandas_progress_apply.py
import pandas as pd
import numpy as np
from tqdm import tqdm
# from tqdm.auto import tqdm # for notebooks
@izikeros
izikeros / add_value_labels.py
Last active February 3, 2022 04:33
Add value labels to matplotlibs' bar or barh
# See: plot_enhancements.py gist
def add_value_labels_barh(ax, spacing=5):
"""
Add labels to the end of each bar in a barh chart.
Tip: usually one need to add expansion of xlimit to keel labels inside plot, e.g.:
ax.set_xlim(0, 1.1)
Arguments:
ax (matplotlib.axes.Axes): The matplotlib object containing the axes
@izikeros
izikeros / useful_pandas_snippets.py
Last active March 14, 2024 09:55 — forked from fomightez/useful_pandas_snippets.py
[useful pandas snippets] useful pandas snippets #pandas #python
# List unique values in a DataFrame column
df['Column Name'].unique()
# convert column to lowercase (without warning working on copy)
df.loc[:, 'url'] = df.loc[:, 'url'].str.lower()
# To extract a specific column (subset the dataframe), you can use [ ] (brackets) or attribute notation.
df.height
df['height']
# are same thing!!! (from http://www.stephaniehicks.com/learnPython/pages/pandas.html
@izikeros
izikeros / convert_pandas_column_type.py
Created August 8, 2019 05:44
convert pandas column to another type without warnings
# convert to datetime without warnings
meta_df= meta_df.astype({'eventDate': 'datetime64'})
@izikeros
izikeros / convert_ssh2_key_to_openssh.sh
Last active July 17, 2024 22:38
[convert ssh2 public key to openssh] Convert ssh2 public key to openssh format and add to authorized_keys #ssh #key
# if received key in format:
#—- BEGIN SSH2 PUBLIC KEY —-
#
#Comment: "rsa-key-20160402"
#AAAAB3NzaC1yc2EAAAABJQAAAgEAiL0jjDdFqK/kYThqKt7THrjABTPWvXmB3URI
#
# and you want to add it to authorized keys
# from: https://tutorialinux.com/convert-ssh2-openssh/
ssh-keygen -i -f coworker.pub >> ~/.ssh/authorized_keys
@izikeros
izikeros / plot_wordcloud_from_dict.py
Created November 15, 2019 09:44
Plot wordcloud from dict in Python
from wordcloud import WordCloud
wordcloud = WordCloud(background_color='white',
width=1500,
height=1000
).generate_from_frequencies(dictionary)
# use .generate(space_separated_string) - to generate cloud from text
plt.figure(figsize=(9,6))
plt.imshow(wordcloud)