Skip to content

Instantly share code, notes, and snippets.

View izikeros's full-sized avatar

Krystian Safjan izikeros

View GitHub Profile
@izikeros
izikeros / useful_pandas_snippets.md
Last active March 15, 2024 19:53 — forked from bsweger/useful_pandas_snippets.md
[pandas snippets (fork)] Useful Pandas Snippets #pandas #snippets

Useful Pandas Snippets

A personal diary of DataFrame munging over the years.

Data Types and Conversion

Convert Series datatype to numeric (will error if column has non-numeric values)
(h/t @makmanalp)

@izikeros
izikeros / dotmagic.py
Created March 13, 2019 06:15
Example of using dotmagic (graphviz diagrams) in Jupyter notebook.
# You might need to install extension first:
# !pip install git+https://github.com/sursingh/dotmagic.git
# Load the magic
%load_ext dotmagic
style='filled'
color='lightblue'
%%dot -p
@izikeros
izikeros / notebook_mem_usage.py
Created April 2, 2019 13:16 — forked from aiguofer/README.md
Find out how much memory each of the jupyter notebooks running on a server is using. Helpful for knowing which ones to shut down. Original code from http://stackoverflow.com/questions/34685825/jupyter-notebook-memory-usage-for-each-notebook
import os
import pwd
import psutil
import re
import string
import requests
import socket
import argparse
import tabulate
import pandas as pd
@izikeros
izikeros / git_rename_branch.sh
Last active February 17, 2022 18:35
Rename currently checked out branch locally and remote
git branch -m new_branch # Rename currently checked out branch locally
git branch -m old_branch new_branch # Rename old_branch to new_branch locally
git push origin :old_branch # Delete the old branch
git push --set-upstream origin new_branch # Push the new branch, set local branch to track the new remote
@izikeros
izikeros / jupyter_autoreload.ipynb
Created May 30, 2019 18:45
Autoreload magic lines for jupyter notebook using external code.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@izikeros
izikeros / pandas_wide_display.py
Last active March 14, 2024 10:02
[wide pandas dataframe] Enable displaying wide dataframes. Utilize wide screen space. #pandas
# Pandas wide display
pd.set_option('display.max_columns', None)
pd.set_option('display.expand_frame_repr', False)
pd.set_option('max_colwidth', -1)
@izikeros
izikeros / isort_hooks.py
Created June 5, 2019 07:19
Git pre-commit hooks adding flake8 and isort checks. Place them in .githooks subdirectory of main project directory.
#!/usr/bin/env python
import sys
from isort.hooks import git_hook
sys.exit(git_hook(strict=True, modify=True))
@izikeros
izikeros / python_file_and_console_logger.py
Created June 12, 2019 09:56
Setup logger printing to console and file.
import logger
import os
import time
LOG_NAME = 'app_name'
LOG_DIR = '../log'
log_fmt = '%(levelname).1s %(message)s'
logging.basicConfig(level=logging.DEBUG, format=log_fmt)
logger = logging.getLogger(__name__)
@izikeros
izikeros / bash-colors.sh
Last active March 14, 2024 09:53
[shell colors] definition of colors to be used for printing coloured messages #bash
# Text color variables
# Sample usage: $bldblu Respository $txtrst is $bldred not clean $txtrst"
txtund=$(tput sgr 0 1) # Underline
txtbld=$(tput bold) # Bold
bldred=${txtbld}$(tput setaf 1) # red
bldblu=${txtbld}$(tput setaf 4) # blue
bldwht=${txtbld}$(tput setaf 7) # white
# Reset
txtrst=$(tput sgr0)
@izikeros
izikeros / tmux-cheatsheet.markdown
Created June 18, 2019 13:56 — forked from MohamedAlaa/tmux-cheatsheet.markdown
tmux shortcuts & cheatsheet

tmux shortcuts & cheatsheet

start new:

tmux

start new with session name:

tmux new -s myname