queirozf.com

Entries by tag: python

Including child/synonym tags

Pytest Examples: Handling Exceptions  18 Oct 2023    python pytest
Examples on how to use Pytest to handle exceptions Read More ›

Python Dependency Management: Examples and Reference  22 Jul 2023    python
Examples on how to use python tools to manage dependencies. Read More ›

Python 3 Regex: Named Capture Examples  25 Jun 2023    python-3 regex
Examples on how to use named capture gropus in Python regular expressions. Read More ›

Pandas Fillna Examples: Filling in Missing Data  16 Oct 2022    pandas
Examples on the most common ways you will find yourself using fillna and related functions in pandas. Read More ›

Pandas Dataframe examples: Plotting Histograms  31 Jul 2022    matplotlib pandas
Several examples on how to draw histograms based on pandas dataframes. Read More ›

Pandas Examples: Looping over Dataframe Rows  13 Jun 2022    pandas
Everything you need to know about how to loop and/or iterate over rows in a pandas dataframe, as efficiently as possible. Read More ›

Python Date/Datetime Arithmetic Examples: Adding, Subtracting, etc  08 May 2022    python datetime
Some examples on how to perform basic arithmetic on Python date and datetime objects, examples on timedelta, etc. Read More ›

Matplotlib Examples: Drawing Straight Lines  06 May 2022    matplotlib
Examples showing you how to draw several types of straight lines on matplotlib, horizontal, vertical, at angles, dashed, solid, etc Read More ›

Pandas Examples: Plotting Date/Time data with Matplotlib/Pyplot  24 Apr 2022    pandas matplotlib
Examples on how to plot time-series or general date or time data from a pandas dataframe, using matplotlib behind the scenes. Read More ›

Python 3 Examples: Creating, Deleting, Updating directories  08 Aug 2021    python files
Lots of examples on how to create, remove, change and otherwise interact with directories with Python 3+ (Assuming unix-like Operating Systems such as Linux and MacOS) Read More ›

Measuring Function Running Times in Python  08 Jul 2021    python
Really simple code to help profile individual method calls to find bottlenecks in Python code. Read More ›

Matplotlib examples: Number Formatting for Axis Labels  29 Jun 2021    matplotlib formatting
Some examples on how to properly format axis labels, add thousands separator, format axis labels to make them easier to read, etc. Read More ›

Matplotlib Examples: Plots with String Axis Labels  28 Jun 2021    matplotlib
Examples on how to create plots where one of the axis is not a list of integers/floats but a list of strings. Read More ›

Pandas Dataframe Examples: Styling Cells and Conditional Formatting  09 May 2021    python pandas
Some examples on how to highlight and style cells in pandas dataframes when some criteria is met. Useful for analytics and presenting data. Read More ›

Python Regular Expressions: Lookahead and lookbehind examples  09 May 2021    python regex
Examples for how and when to use lookaheads and lookbehinds in python regular expressions. These are ways to create matches that depend on what came before or what came after the pattern you want to match. Read More ›

Normalize Text for Natural Language Processing Tasks: Reference and Examples  02 May 2021    nlp preprocessing python
A couple of common preprocessing tasks you need in order to be able to use raw text in NLP tools. Read More ›

Python Datetime with Timezones: Examples and Reference  03 Jan 2021    python datetime timezones
Examples on how to work with datetimes and timezones, using the standard python library, datetime. Read More ›

Suppressing, Ignoring Warnings in Python: Reference and Examples  11 Nov 2020    python
Examples on how to suppress warnings in python code, when needed. Can be used in standalone scripts, structured systems and/or jupyter notebooks. Read More ›

Pandas Dataframes: Apply Examples  26 Sep 2020    pandas
Examples on how to use pandas apply, on columns, dataframes, etc, with best practices and warnings about performance. Read More ›

Python: Working with Paths & the Filesystem  26 Sep 2020    python files paths
Several examples on how to work with paths and files in python, convert from relative to aboslute paths, check if a path points to a valid file, etc. Read More ›

Pytest Options: Best Practices and Examples  23 Aug 2020    pytest python testing
Examples on how to use pytest to run tests, configure outputs, etc. Read More ›

Python Imports: Reference and Examples  25 Apr 2020    python jupyter-notebooks
Examples on how to deal with imports in Python scripts and jupyter notebooks, how to add custom directories and import from those, etc. Read More ›

Matplotlib Subplots: Best Practices and Examples  20 Apr 2020    matplotlib
Examples on how to plot multiple plots on the same figure using Matplotlib and the interactive interface, pyplot. Includes common use cases and best practices. Read More ›

Numpy Display Options: Examples and Reference  24 Mar 2020    numpy
Number formatting, array visualization and other options to visualize numpy elements, being especially useful for working in Jupyter notebooks. Read More ›

Pandas Display Options: Examples and Reference  24 Mar 2020    pandas
Variety of examples on how to set display options on Pandas, to control things like the number of rows, columns, number formatting, etc. Especially useful for working in Jupyter notebooks. Read More ›

Pandas Dataframes: CSV Quoting and Escaping Strategies  24 Mar 2020    pandas
Reading and writing pandas dataframes to CSV files in a way that's safe and avoiding problems due to quoting, escaping and encoding issues. Read More ›

Scikit-learn Pipelines: Custom Transformers and Pandas integration  08 Mar 2020    pandas scikit-learn
Examples and reference on how to write customer transformers and how to create a single sklearn pipeline including both preprocessing steps and classifiers at the end, in a way that enables you to use pandas dataframes directly in a call to fit. Read More ›

Numpy Sampling: Reference and Examples  07 Mar 2020    numpy statistics
Sample from probability distributions and from lists, with and without weights. Examples using Python, Numpy and Scipy. Read More ›

Python Unittest Examples: Mocking and Patching  09 Dec 2019    python testing
Simple examples to help you understand when/where to use mocking and patching, so you don't need to skip testing any part of your code. Read More ›

Pandas Dataframe Examples: Duplicated Data  17 Nov 2019    pandas
Deal with duplicated data in pandas: drop, count, show and mark duplicates in pandas dataframes. Read More ›

Matplotlib Errorbar Examples  06 Nov 2019    matplotlib
Examples on how to plot data including spread information such as standard deviations, variance, etc. Read More ›

Conda, Pip, Virtualenv and Pyenv: Commands Compared  16 Sep 2019    pip conda virtualenv
Equivalent commands for conda on the one hand and pip plus virtualenv on the other. Read More ›

Python Open File: Reference and Examples  15 Sep 2019    python files
Quick reference for how to open files in Python, encodings, modes, etc. Read More ›

Python 3 String Operations  11 Sep 2019    python-3 strings
Common operations you will need to do on python strings, within the context of Natural Language Processing (NLP) or otherwise. Read More ›

Pandas Indexing Examples: Accessing and Setting Values on DataFrames  21 Aug 2019    pandas dataframes
Some common ways to access rows in a pandas dataframe, includes label-based (loc) and position-based (iloc) accessing. Read More ›

Choosing C Hyperparameter for SVM Classifiers: Examples with Scikit-Learn  20 Jun 2019    scikit-learn svm
Analysis of the effect of the C parameter on learning SVM models under a noisy data regime. With examples using the Python Library Scikit-learn. Read More ›

Pandas Dataframe Examples: String Functions  01 Jun 2019    pandas
Pandas exposes a series of string methods that you can use on Series that contain string objects. These are useful for filtering dataframes among other uses. Read More ›

Pandas Dataframe Examples: Create and Append data  25 Mar 2019    pandas
Examples on how to create dataframes, using lists, dicts and creating empty dataframes then initializing it with data. Read More ›

Matplotlib Examples: Displaying and Configuring Legends  23 Mar 2019    matplotlib
Multiple examples on how to display and customize legends on matplotlib plots. Read More ›

Pandas Time Series Examples: DatetimeIndex, PeriodIndex and TimedeltaIndex  10 Mar 2019    datetime pandas time-series
How and when to use special pandas Indexes such as DatetimeIndex, PeriodIndex and TimedeltaIndex. These will help you deal with and perform simple operations on time-series data. Read More ›

Pandas Concepts: Reference and Examples  10 Mar 2019    pandas
Short explanations with examples on the main concepts you'll find when using the Pandas library. Read More ›

Pandas Dataframe Examples: Manipulating Date and Time  15 Jan 2019    pandas datetime
Some examples on how to manipulate dates and times in pandas Dataframes, perform date arithmetic, etc. Read More ›

Pandas Dataframe Examples: Column Operations  09 Dec 2018    pandas dataframes
Examples on how to modify pandas DataFrame columns, append columns to dataframes and otherwise transform individual columns. Read More ›

Numpy Array (ndarray) Examples  08 Dec 2018    numpy
Numpy Array-like data structures (ndarrays) are the bread and butter of a lot of data work done these days. Read More ›

Python 3 Subprocess Examples  03 Nov 2018    python3
Examples on how to spawn and control OS-level processes from a python script, using the new Subprocess module. Read More ›

Interactive controls for Jupyter notebooks: Python Examples  20 Sep 2018    jupyter python
Examples on how to add interactive controls to jupyter notebooks. Read More ›

Caching Function Results in Python: Examples using Joblib and Functools  15 Sep 2018    python caching
In many cases (web development, data analysis, etc) it's useful to be able to store results that take long to re-compute. These solutions allow you to save results (either in memory or on disk) so that all function calls after the first one become constant-time lookups. Read More ›

Heads-up for Deploying Scikit-learn Models to Production: Quick Checklist  01 Sep 2018    scikit-learn production machine-learning-engineering
A couple of tips for addressing common problems and unexpected situations when using scikit-learn models in production.. Read More ›

Cross-Validation Examples with Scikit-Learn  01 Sep 2018    scikit-learn
Using cross-validation within scikit-learn. Read More ›

Mutate for Pandas Dataframes: Examples with Assign  15 Jul 2018    pandas
Assign is a function that mutates a dataframe in place and can be used for chained operations. Read More ›

Pandas Query Examples: SQL-like queries in dataframes  05 Jul 2018    pandas
Use SQL-like syntax to perform in-place queries on pandas dataframes. Read More ›

Example Project Template: Serve a Scikit-learn Model via a Flask API  27 Jun 2018    flask scikit-learn
Full (albeit simple) example on how to create a simple Flask API to serve predictions using a pre-trained scikit-learn model. Includes supporting features such as logging, error handling, input validation, etc. Full code available on Github. Read More ›

Add Labels and Text to Matplotlib Plots: Annotation Examples  23 Jun 2018    matplotlib labels annotation
Examples on how to add simple annotations and labels to your matplotlib plots. Read More ›

Pandas Dataframe: Union and Concat Examples  14 Jun 2018    pandas
Emulate SQL union and union all behaviour, among other stuff. Read More ›

Scikit-Learn examples: Making Dummy Datasets  02 May 2018    scikit-learn
Make dummy datasets to test out classifiers and/or parameter configurations in Scikit-learn. Read More ›

Visualizing Machine Learning Models: Examples with Scikit-learn, XGB and Matplotlib  23 Apr 2018    matplotlib machine-learning scikit-learn
Examples on how to use matplotlib and Scikit-learn together to visualize the behaviour of machine learning models, conduct exploratory analysis, etc. Read More ›

Pandas Dataframe: Merge and Join Examples  17 Apr 2018    pandas
Examples on how to use pandas.merge to do SQL-style joins on pandas dataframes. Read More ›

Python Dict Examples  31 Mar 2018    python
Examples of common dict operations. Includes mapping, filtering, dict comprehension and how to work with ordered dicts. Read More ›

Python Docstrings: Reference & Examples  24 Feb 2018    python documentation testing
Examples to help you document your Python code using any of the commonly used docstring styles. Read More ›

Python Logging: Reference and Examples  17 Feb 2018    python logging
Examples on how to setup and configure logging in Python applications. Examples include log rotation, log rotation with compression, logging in Flask applications, etc. Read More ›

Python Unit Testing with unittest: Reference and Examples  12 Feb 2018    python testing
Testing is needed in all but the most trivial applications. The unittest module is very widely used in Python because it's part of the standard library, starting with Python 2.1. Read More ›

Pandas Dataframe: Plot Examples with Matplotlib and Pyplot  22 Dec 2017    pandas pyplot matplotlib dataframes
Examples on how to plot data directly from a Pandas dataframe, using matplotlib and pyplot. Read More ›

Python CSV Module: Reference and Examples  12 Dec 2017    python csv
Examples on how to read and write CSV files and configure Python's CSV module. Read More ›

Package a Python Project and Make it Available via pip install: Simple Example  15 Nov 2017    python data-newsletter-6
It's easy to package some code you wrote as a package. Publish your Python code to PyPi to have other people use and contribute to it! Read More ›

Pip Install a Project having a setup.py file: an Example  11 Nov 2017    python
You can use pip to install a Python project that uses a setup.py setup file. Read More ›

Python number formatting examples  05 Nov 2017    python formatting
Examples on how to format numbers in Python, e.g. rounding, truncating, etc. Read More ›

Scikit-Learn Pipeline Examples  21 Oct 2017    scikit-learn
Examples of how to use classifier pipelines on Scikit-learn. Includes examples on cross-validation regular classifiers, meta classifiers such as one-vs-rest and also keras models using the scikit-learn wrappers. Read More ›

Python on Jupyter notebooks: Reference for Common Use Cases  16 Oct 2017    jupyter python
Getting more done with Jupyter notebook, with useful shortcuts and commonly-used functionality. Read More ›

Pandas DataFrame: GroupBy Examples  11 Oct 2017    pandas groupby
Examples of specific ways to do what you want using groupby on Pandas Dataframes. Read More ›

Matplotlib: Pyplot By Example  05 Oct 2017    pyplot matplotlib
Examples for common operations on PyPlot, like changing figure size, changing title and tick sizes, changing legends, etc. Read More ›

Parallel For Loops in Python: Examples with Joblib  02 Oct 2017    python parallel
Joblib.Parallel is a simple way to spread your for loops across multiple cores, for parallel execution. Read More ›

Feature Scaling: Quick Introduction and Examples using Scikit-learn  27 Sep 2017    data-science python data-preprocessing
Feature Scaling techniques (rescaling, standardization, mean normalization, etc) are useful for all sorts of machine learning approaches and *critical* for things like k-NN, neural networks and anything that uses SGD (stochastic gradient descent), not to mention text processing systems. Included examples: rescaling, standardization, scaling to unit length, using scikit-learn. Read More ›

Matplotlib, Pyplot, Pylab etc: What's the difference between these and when to use each?  26 Sep 2017    python data-visualization data-newsletter-5
Do you often get confused with terms like maptlotlib, pyplot, pylab, figures, axes, gcf, gca, etc and wonder what they mean? Matplotlib is the toolkit, PyPlot is an interactive way to use Matplotlib and PyLab is the same thing as PyPlot but with some extra shortcuts. Read More ›

Seaborn by Example: Data Visualization and Plotting using Python  09 Sep 2017    python data-visualization plotting
Seaborn is a higher-level interface to Matplotlib. It has a more convenient API and has useful data visualization functions right out of the box. Read More ›

Pandas for Large Data: Examples and Tips  13 Aug 2017    pandas performance
In order to successfully work with large data on Pandas, there are some ways to reduce memory usage and make sure you get good speed performance. Read More ›

Python Pickle: examples and reference  12 Jul 2017    python pickle
Pickle is a well-known Python tool for saving arbitrary variable contents into file. Here are a couple of examples and tips on how you can use it to make your data science work more efficient and easily reproducible. Read More ›

Scikit-Learn Cheatsheet: Reference and Examples  10 Mar 2017    scikit-learn
Just a couple of things you may find yourself doing over and over again when working with scikit-learn. Read More ›

Python Json Module: Reference and Examples  16 Jan 2017    python json
Examples and best practices for using the python json module. Includes common operations such as reading, writing and formatting as well as solutions to common problems. Read More ›

Python Command-Line Scripts: Reference  04 Jan 2017    python cli command-line
Setup Keras+Theano Backend and GPU on Ubuntu 16.04  11 Sep 2016    keras gpu theano
A couple of pointers on how to get up and running with Keras and Theano on a clean 16.04 Ubuntu machine. Read More ›

Numpy/Scipy Distributions and Statistical Operations: Examples & Reference  10 Sep 2016    numpy statistics
A couple of examples of things you will probably want to do when using numpy and scipy for data work, such as probability distributions, PDFs, CDFs, etc. Read More ›

Python Datetime Examples  04 Jul 2016    python3 date datetime
Examples on how to create and manipulate date and datetime objects using Python. Read More ›

Working with Files & Directories in Python  26 Mar 2016    python
Examples on how to perform filesystem-related tasks using python. Tasks include reading and writing to files, listings files and manipulating the path. Read More ›

Python Environment Overview  25 Mar 2016    python
Short and concise descriptions of the major projects/tools related to managing python projects, dependencies and environments. Includes information on Anaconda, Pip, Virtualenv and related projects. Read More ›

Python Regular Expressions: Examples & Reference  17 Mar 2016    python-3 regular-expressions
Pandas DataFrame by Example  15 Dec 2015    pandas python
Lots of examples of ways to use one of the most versatile data structures in the whole Python data analysis stack. Learn how to slice and dice, select and perform commonly used operations on DataFrames. Read More ›

One-Hot Encoding a Feature on a Pandas Dataframe: Examples  27 Nov 2015    pandas
One-hot encoding is a simple way to transform categorical features into vectors that are easy to deal with. Learn how to do this on a Pandas DataFrame. Read More ›

Spark SQL: Examples on pyspark  18 Oct 2015    pyspark spark-sql
Functional Programming with Python: Quick Reference with Examples  16 Apr 2015    python functional programming
Getting started with Python NLTk on Ubuntu  29 Mar 2015    python nltk
Python Virtualenv Examples  19 Jun 2014    pip virtualenv
How to Install pip on Ubuntu  02 Jun 2014    ubuntu pip
Python 1-Minute Tutorial for Those with Previous Programming Experience  20 Feb 2014    python
Add Colour to Text on the Terminal: Examples with Bash and Python  09 Aug 2012    bash python