Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
259 views

Numpy Pandas Cheatsheet PDF

This document provides a cheat sheet summarizing common functions for working with NumPy arrays, Pandas Series, and Pandas DataFrames. It includes functions for accessing and summarizing data, vectorized operations, plotting, and applying functions to arrays, Series and DataFrames.

Uploaded by

Shailesh Kumar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
259 views

Numpy Pandas Cheatsheet PDF

This document provides a cheat sheet summarizing common functions for working with NumPy arrays, Pandas Series, and Pandas DataFrames. It includes functions for accessing and summarizing data, vectorized operations, plotting, and applying functions to arrays, Series and DataFrames.

Uploaded by

Shailesh Kumar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Numpy and Pandas Cheat Sheet Array / Series functions Accessing Data in a DataFrame

max() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Maximum df[’col’] . . . . . . . . . . . . . . . . . . . . . . . Get column by name


min() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Minumum df.iloc[i] . . . . . . . . . . . . . . . . . . . . . . Get row by position
Common Imports df.loc[x] . . . . . . . . . . . . . . . . . . . . . . . . . . Get row by index
mean(). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Mean (average)
import numpy as np df.iloc[i, j] . . . . . . . . . . . . . . . Get element by position
median() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Median
import pandas ps pd df.loc[x, y] . . . . . . . . . . . . . . . . . . . Get element by index
sum(). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Sum (total) df.values . . . . . . . . . . . . . . . . . . . . . . Get 2D NumPy array
import matplotlib.pyplot as plt
import seaborn as sns
Accessing Data in a Series DataFrame Summarization
s.iloc[i] . . . . . . . . . . . . . . . . . . . . Get element by position df.describe() . . . . . . . . . . . . . . Stats about each column
Vectorized Operations
s.loc[x] . . . . . . . . . . . . . . . . . . . . . . . Get element by index df.head(n) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . First n rows
xs + ys . . . . . . . . . . . . . . . . . . . . . . . . Element-wise addition
s.values . . . . . . . . . . . . . . . . . . . . . . . . . . . Get NumPy array df.tail(n) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Last n rows
xs + z . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Adding a scalar df.columns . . . . . . . . . . . . . . . . . . . . . List of column names
xs & ys . . . . . . . . . . . . . . . . . . . . . . . . Bitwise (boolean) and
xs | ys . . . . . . . . . . . . . . . . . . . . . . . . . . bitwise (boolean) or Plotting for Series
xs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Bitwise (boolean) not s.hist() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Histogram Axis Argument
df.mean(axis=0) . . . . . . . . . . . . . . . mean of each column
xs < ys . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Less than s.plot(). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Line plot
df.mean(axis=1) . . . . . . . . . . . . . . . . . . . mean of each row
df.mean(axis=’index’) . . . . . . . . mean of each column
Subtraction (-), multiplication (*), division (/), expo- df.mean(axis=’columns’ . . . . . . . . . . . . . . . . . . . . . . . . . . . )
nentiation (**), and other comparison operators (<=, Apply Functions
s.apply(value -> value) . . . . . . . . . . . returns a Series mean of each row
>, >=, ==, !=) work similarly.
df.applymap(value -> value) . returns a DataFrame
df.apply(series -> value) . . . . . . . . . returns a Series Plotting for DataFrames
matplotlib plotting df.apply(series -> series). . .returns a DataFrame df.plot() . . . . . . . . . Line plot with one line per column
plt.hist(xs). . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Histogram
plt.scatter(xs, ys) . . . . . . . . . . . . . . . . . . . . . Scatterplot
plt.plot(xs, ys) . . . . . . . . . . . . . . . . . . . . . . . . . . Line plot

You might also like