Python Code Examples


Explore our Python code examples here. These python code snippets can help you understand Python better, whether you’re a beginner or an advanced coder.

Plot 3 different Pandas Dataframes in the same chart

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.

conda upgrade all packages

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