Pandera Schema Model
pandera
supports built-in python types or strings representing the legal pandas datatypes, or pandera’s DataType:
pandera
supports built-in python types or strings representing the legal pandas datatypes, or pandera’s DataType:
Quick Start Code Example of the pandera library.
A complete example that exposes prometheus metrics endpoint under /metrics/ path in starlette.
A complete example that exposes prometheus metrics endpoint under /metrics/ path in starlette.
The following starlette-wtf code example implements a simple form handler with CSRF protection. The form has a required string field and validation errors are handled by the html template.
Starlette-WTF provides a form class that makes it easy to add form validation and CSRF protection to Starlette apps.
import pandas as pd
import numpy as np
from matplotlib import pyplot as plt
#using numpy's randint to generate some data
df1 = pd.DataFrame(np.random.randint(0,100,size=(10, 2)), columns=list('XY'))
df2 = pd.DataFrame(np.random.randint(0,100,size=(10, 2)), columns=list('XY'))
df3 = pd.DataFrame(np.random.randint(0,100,size=(10, 2)), columns=list('XY'))
df1.head(), df2.head(), df3.head()
( X Y
0 82 32
1 79 13
2 87 19
3 6 73
4 1 38,
X Y
0 47 62
1 41 0
2 98 78
3 63 83
4 31 59,
X Y
0 57 25
1 49 27
2 9 29
3 93 75
4 23 80)
# Get handle of first figure to pass to other plot() calls as ax
ax = df1.plot(color="red", figsize=(10,5))
df2.plot(ax=ax, color="orange", figsize=(10,5))
df3.plot(ax=ax, color="green", figsize=(10,5))
# Note: subsequent plots need to happen in the same notebook cell.
<AxesSubplot:>
In this example Python code, we use requests
to fetch data from the EIA.gov website and json
from the Python standard library to parse the json data. Next, we load the daily prices into a Pandas
DataFrame and format the date column and set it as the index. Finally, we use Pandas .plot() to create a chart saving it as a png image.
Sumy uses nlp to summarize content on webpages and in text files. The below sumy
code example fetches a wikipedia page and extacts a 10 sentence summary.
Starlette routing can be composed in many different ways. Here is a simple example from Starlette’s documentation.
code examples for reading csv files from python. In the example we will import csv
from the python standard library.
conda is an alternative package management tool bundled with the Anaconda python distribution. In some ways conda is a replacement for pip.
Here is how you upgrade all conda installed python packages with one command.
conda update --all
# update all packages unprompted
conda update --all -y
# list packages that can be updated
conda search --outdated
Here are a few examples of pretty printing json from a command line terminal. As you can see in the example output, rich
console can output json with proper indention and color syntax highlighting.
A Python Dictionary to translate US States to Two letter codes
License: Public Domain
{< gistcomments rogerallen 1583593 >}
This python code example will show you how to get the index and value of list items inside a for loop.
Sometimes you just need to quickly serve some files over http from the command line. The http.server allows you to do this.
code examples for reading csv files from python. In the example we will import csv
from the python standard library.
The following beanie model will result in documents being saved into a MongoDB collection named Person
. What if we want our collection to be named people
?