Skip to content

Instantly share code, notes, and snippets.

View flutefreak7's full-sized avatar

Brett Ables flutefreak7

View GitHub Profile
@flutefreak7
flutefreak7 / update pandas vs dict demo.py
Created October 30, 2020 19:23
Comparing pandas update vs dict update
import pandas as pd
data1 = pd.DataFrame({'A': [1, 2, 3, 4]}, index=[0, 1, 2, 3])
data2 = pd.DataFrame({'A': [10, 11, 12, 13]}, index=[2, 3, 4, 5])
data3 = data1.copy()
data3.update(data2)
print(data3)
data1 = pd.DataFrame({'A': [1, 2, 3, 4]}, index=[0, 1, 2, 3])
data2 = pd.DataFrame({'A': [10, 11, 12, 13]}, index=[2, 3, 4, 5])
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@flutefreak7
flutefreak7 / gist:bd621a9a836c8224e92305980ed829b9
Last active October 31, 2021 04:33
Convex Hull with vtk, pyvista, and scipy
import numpy as np
from scipy.spatial import ConvexHull
from pyvista import PolyData
def polyhull(x, y, z):
hull = ConvexHull(np.column_stack((x, y, z)))
faces = np.column_stack((3*np.ones((len(hull.simplices), 1), dtype=np.int), hull.simplices)).flatten()
poly = PolyData(hull.points, faces)
return poly
@flutefreak7
flutefreak7 / pandas_to_latex.py
Created April 30, 2019 06:03
augment pandas to_latex() with vertical bars, multicolumn midrules, first column alignment options, and header formatting
import re
import numpy as np
def pandas_to_latex(df_table, latex_file, vertical_bars=False, right_align_first_column=True, header=True, index=False,
escape=False, multicolumn=False, **kwargs) -> None:
"""
Function that augments pandas DataFrame.to_latex() capability.
:param df_table: dataframe
:param latex_file: filename to write latex table code to
@flutefreak7
flutefreak7 / bokeh_interactive.ipynb
Last active April 4, 2019 20:07
Interactive bokeh plot with ipywidget slider and variable number of curves
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@flutefreak7
flutefreak7 / PyQtGraph QDarkStyle fix
Created February 25, 2019 07:16
This adds a PlotWidget element to the QDarkStyle stylesheet so that axes labels in PyQtGraph plots aren't covered by unnecessary padding.
from PyQt5 import QtCore, QtWidgets
import qdarkstyle
import pyqtgraph as pg
qss_plot_widget = r'''
PlotWidget {
padding: 0px;
}
@flutefreak7
flutefreak7 / jupyter_calendar.py
Last active January 18, 2024 06:59
Make an HTML calendar in a Notebook and highlight some days...
# intended for use in a Jupyter Notebook or similar.
import calendar
from calendar import HTMLCalendar
from IPython.display import HTML
# Based on https://stackoverflow.com/a/1458077/1639671
class HighlightedCalendar(HTMLCalendar):
def __init__(self, highlight=[], *args, **kwargs):
super().__init__(*args, **kwargs)
self._highlight = highlight
@flutefreak7
flutefreak7 / multiproc_queues.py
Last active September 30, 2021 05:42
A python 3.6 demo that creates a PyQt5 GUI which demonstrates multiprocessing with VTK (3d plotting library) and Queues.
from PyQt5 import QtCore, QtWidgets
import sys
from multiprocessing import Process, Queue
from time import time
import vtk
from vtk.qt.QVTKRenderWindowInteractor import QVTKRenderWindowInteractor
import numpy as np
from time import sleep
@flutefreak7
flutefreak7 / keybase.md
Last active September 6, 2019 15:00
keybase for Brett Ables

Keybase proof

I hereby claim:

  • I am flutefreak7 on github.
  • I am brettables (https://keybase.io/brettables) on keybase.
  • I have a public key ASDuxfrIiBFgrsLv4VtJkq7gAY_iKW9gW1Dk5uBbrQezNQo

To claim this, I am signing this object: