A personal diary of DataFrame munging over the years.
Convert Series datatype to numeric (will error if column has non-numeric values)
(h/t @makmanalp)
A personal diary of DataFrame munging over the years.
Convert Series datatype to numeric (will error if column has non-numeric values)
(h/t @makmanalp)
| import os | |
| import pwd | |
| import psutil | |
| import re | |
| import string | |
| import requests | |
| import socket | |
| import argparse | |
| import tabulate | |
| import pandas as pd |
| """ | |
| 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 |
| # 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 |
| #!/bin/bash | |
| USER=${1:-sebble} | |
| STARS=$(curl -sI https://api.github.com/users/$USER/starred?per_page=1|egrep '^Link'|egrep -o 'page=[0-9]+'|tail -1|cut -c6-) | |
| PAGES=$((658/100+1)) | |
| echo You have $STARS starred repositories. | |
| echo |
| # This is an example PKGBUILD file. Use this as a start to creating your own, | |
| # and remove these comments. For more information, see 'man PKGBUILD'. | |
| # NOTE: Please fill out the license field for your package! If it is unknown, | |
| # then please put 'unknown'. | |
| # Maintainer: Your Name <youremail@domain.com> | |
| pkgname=NAME | |
| pkgver=VERSION | |
| pkgrel=1 | |
| epoch= |
| #!/bin/bash | |
| TEMPFILE='/tmp/restic_ignores.txt' | |
| BACKUPDIR=$HOME | |
| # Note: Not sure which way is better, echo nothing into the file, or remove if exists | |
| # if [ -f $TEMPFILE ]; then | |
| # rm $TEMPFILE | |
| # fi | |
| # touch $TEMPFILE |
| #!/usr/bin/env bash | |
| set -Eeuo pipefail | |
| trap cleanup SIGINT SIGTERM ERR EXIT | |
| script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd -P) | |
| usage() { | |
| cat <<EOF | |
| Usage: $(basename "${BASH_SOURCE[0]}") [-h] [-v] [-f] -p param_value arg1 [arg2...] |
| from IPython.display import display | |
| import pandas as pd | |
| def pdshow(df): | |
| """ | |
| This shows a pandas dataframe in full/ | |
| Also consider .to_html() and https://pbpython.com/dataframe-gui-overview.html |