Thanks to visit codestin.com
Credit goes to github.com

Skip to content

carbonatezero/numpy.matplotlib.panda.101

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 

Repository files navigation

A Short Reference for NumPy, Matplotlib, and Pandas

Commonly used operations and notes for scientific computing and data visualization in Python.

NumPy

https://numpy.org/doc/stable/user/quickstart.html

Quickstart Jupyter notebook:
https://github.com/carbonatezero/np_plt_pd_abs_basics/blob/main/quick_starts_numpy.ipynb

Matplotlib

https://matplotlib.org/stable/tutorials/introductory/usage.html

Shortest example:

import matplotlib.pyplot as plt  

fig, ax = plt.subplots() 
ax.plot(a, b)  # a and b are NumPy arrays

Figure

  • fig = plt.figure(): create an empty figure with no Axes (pyplot-style)
  • fig, ax = plt.subplots(): create a figure with a single Axes (OO-style)
  • fig, ax = plt.subplots(2, 2): create a figure with a 2×2 grid of Axes

Axes

  • The Axes class and its member functions are the main entry point for the OO interface.
  • For each Axes method, there is a corresponding function in matplotlib.pyplot that operates on the current axes.

Change parts of a figure

  • ax.set_title()

  • ax.legend()

  • ax.set_xlabel(), ax.set_ylabel()

  • ax.set_yscale('log')

  • ax.tick_params(**kwargs) Example: kwargs = {'labelsize': 14}

  • Recommended helper function:

    def my_plotter(ax, data1, data2, param_dict):
        out = ax.plot(data1, data2, **param_dict)
        return out
  • Convert all inputs (e.g. from pandas.DataFrame) to numpy.array objects before plotting.

  • Prefer the OO-style interface.

Pandas

https://pandas.pydata.org/docs/getting_started/intro_tutorials/index.html

Two primary data structures

  • Series: one-dimensional container of scalars
  • DataFrame: two-dimensional container of Series

Built on top of NumPy

Read and write tabular data

Use functions such as pd.read_csv(), pd.to_csv(), pd.read_excel(), etc.

Select a subset of a DataFrame

  • Select specific columns

    • df["Age"] → returns a Series
    • df[["Age"]] → returns a DataFrame
  • Filter specific rows

    • df[df["Age"] > 35] (returns rows where the condition is true)
  • Select specific rows and columns

    • df.loc[df["Age"] > 35, "Name"]
    • df.iloc[9:25, 2:5]

About

Daily used Numpy Matplotlib Pandas SHORT references

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published