Skip to content

Instantly share code, notes, and snippets.

View tchiavegatti's full-sized avatar

Tiago Chiavegatti tchiavegatti

View GitHub Profile
@tchiavegatti
tchiavegatti / func_filepath.py
Created January 31, 2020 19:25
[Storage filepath] Function to set a filepath to a dataframe storage in feather, HDF5, CSV or Excel #pandas
def filepath(filetype, destination, version=None, tag=tag):
"""
Returns a filepath to for file export.
Attributes:
filetype: `str`, 'feather', 'hdf', 'csv', 'excel'
Type of the output file. Implemented to date are feather, hdf5 (h5), csv and Excel (xlsx).
destination: `str`, 'data' or 'output'.
Whether the file should be exported to the data folder or to the output folder. \
HDF5 and feather files storing temporary data can go to the data folder. \
@tchiavegatti
tchiavegatti / working_with_columns.py
Last active November 15, 2021 20:57
[Usefull stuff related to columns on Pandas] #pandas
# Find column index
df.columns.get_loc('col_name')
# The other way around (find column name using the index)
df.columns.get_values()[index]
# Find indices of multiple columns
def column_index(df, query_cols):
``` Get indices of multiple columns.
https://stackoverflow.com/a/38489403
@tchiavegatti
tchiavegatti / check_version.py
Last active November 15, 2021 20:57
[Check python version on a Jupyter notebook] #jupyter
# Check version runing on Jupyter notebook
from platform import python_version
print(python_version())
# Check version inside your Python program
import sys
print(sys.version)
# Check version in command line or shell
python --version
@tchiavegatti
tchiavegatti / change_column_order
Last active March 10, 2022 21:45
Reorder one or several columns of a dataframe #pandas
def change_column_order(df, col_position):
'''Reorder one or several columns of a dataframe.
Based on the function described at https://stackoverflow.com/a/37071454.
Parameters
----------
df : pandas dataframe
col_position : dict
{'Column' : index where the column should be}
@tchiavegatti
tchiavegatti / python-batchfile.bat
Created May 6, 2019 14:08 — forked from jadient/python-batchfile.bat
Run python code directly from a batch file
@echo off & python -x "%~f0" %* & goto :eof
# ==========================================================
# one way to place python script in a batch file
# place python code below (no need for .py file)
# ==========================================================
import sys
print "Hello World!"
for i,a in enumerate(sys.argv):
@tchiavegatti
tchiavegatti / instructions.md
Created April 1, 2018 20:56 — forked from zentralwerkstatt/instructions.md
Install Syncthing on Raspberry Pi
  • Install the necessary packages:
sudo apt-get install apt-transport-https ca-certificates
curl -s https://syncthing.net/release-key.txt | sudo apt-key add -
echo "deb http://apt.syncthing.net/ syncthing release" | sudo tee /etc/apt/sources.list.d/syncthing.list
sudo apt-get update
sudo apt-get install syncthing
sudo apt-get install git
  • Start syncthing once: