Skip to content

Instantly share code, notes, and snippets.

View data-enhanced's full-sized avatar

David Cochran data-enhanced

View GitHub Profile
@data-enhanced
data-enhanced / pandas_describe_formatted.md
Last active November 21, 2025 08:14
Format output of pandas describe() method

Pandas .describe() formatted

Format numbers output from the pandas df.describe() method. For instance, instead of outputting scientific notation, we can have numbers with thousands separators and a desired number of decimals.

When using .describe with an entire dataframe, use .apply and a lambda function to apply the formatting to every number.

  • To change the number of decimals, change the number before the f
  • To remove the thousands separator remove the comma

df.describe().apply(lambda s: s.apply('{:,.0f}'.format))

When using .describe with a single column or a series, use the .map method instead:

@data-enhanced
data-enhanced / jupyter_default_browser.md
Last active July 24, 2025 08:51
Change default browser for Jupyter Notebooks in Mac OS X

Change the Default Browser for Jupyter Notebooks in OS X

Step 1. Create an editable config file for Jupyter notebooks.

To do this, open Terminal and type:

jupyter notebook --generate-config

This generates the file:

~/.jupyter/jupyter_notebook_config.py

HTML5 Markup Template - Basic

A very basic starter template with fundamental HTML5 markup -- only the basics.

Based on HTML5 Bones | http://html5bones.com

# Format using Markdown ================================================
# Format Jupyter Code Output using Markdown
# https://ipython.readthedocs.io/en/stable/api/generated/IPython.display.html?highlight=display_markdown#IPython.display.display_markdown
from IPython.display import display_markdown
markdowntext = 'Markdown Heading Level 3'
display_markdown(f'### Code Output Formatted as {markdowntext}', raw=True)
display_markdown(f'_Code output italicized using_ `display_markdown`', raw=True)
@data-enhanced
data-enhanced / model_reports.py
Created February 25, 2022 02:31
Custom function to generate a report for a binary classification model that includes the model, scores, and confusion matrix.
# Function for generating model scores and confusion matrices with custom colors and descriptive labels
# https://stackoverflow.com/questions/70097754/confusion-matrix-with-different-colors
# https://medium.com/@dtuk81/confusion-matrix-visualization-fc31e3f30fea
def report_scores(model, features, labels):
'''
Generating model scores and confusion matrices with custom colors and descriptive labels
model = model variable
features = features of desired split
labels = labels of desired split
@data-enhanced
data-enhanced / vs-code-turnoff-autocomplete.json
Last active October 3, 2020 03:18
Turn off autocompletion (intellisense) in MS Visual Studio Code
// Turn off autocomplete in Visual Studio Code
// http://code.visualstudio.com/
// Add the following lines to user settings
// OPTIONAL WORD WRAPPING
// Controls if lines should wrap. The lines will wrap at min(editor.wrappingColumn, viewportWidthInColumns).
"editor.wordWrap": true,
// Controls the indentation of wrapped lines. Can be one of 'none', 'same' or 'indent'.
"editor.wrappingIndent": "indent",
@data-enhanced
data-enhanced / mixins-multiple-transitions.less
Created February 25, 2013 15:44
LESS mixin to handle multiple CSS transitions together
// Handling Multiple Transitions
// http://stackoverflow.com/questions/5510568/multiple-properties-are-getting-treated-as-separate-arguments-in-mixins
.bitbr-transition(@value1,@value2:X,...)
{
@value: ~`"@{arguments}".replace(/[\[\]]|\,\sX/g, '')`;
-webkit-transition: @value;
-moz-transition: @value;
-ms-transition: @value;
-o-transition: @value;
@data-enhanced
data-enhanced / Remove_json_from_TMDB_fields.py
Last active March 6, 2020 00:42
Remove json formatting from TMDB fields
# Import ast for ast.literal_eval
import ast
# Remove JSON from TMDB fields
# for genres, spoken_languages, production_companies, production_countries
# Works only with non-null values, so filter out null values before applying
# Requires import ast -- or use simply eval vs ast.literal_eval
def remove_json(content):
# Interpret the content as a Python list of dictionaries
content = ast.literal_eval(content)
@data-enhanced
data-enhanced / apply_function_pd_column.py
Created February 17, 2020 20:57
Apply a function to a pandas column
# Define a function to get the name field from the first item in a dictionary list
def get_genre1(x):
x = json.loads(x)
if len(x) > 0:
return x[0]['name']
# Now use pandas.apply to use the function on one column
# In thise case create a new column called genres1 to hold the new data
movies['genre1'] = movies['genres'].apply(get_genre1)
@data-enhanced
data-enhanced / gist:1a3b5dfc0ec750a066ee
Created June 9, 2015 18:37
WP excerpt remove p tags
<?php
$myExcerpt = get_the_excerpt();
$tags = array("<p>", "</p>");
$myExcerpt = str_replace($tags, "", $myExcerpt);
echo $myExcerpt;
?>
<!-- https://wordpress.org/support/topic/remove-ltpgt-tag-from-excerpt -->