Anacoda&Jupyter DAY 05 Pandas绘图&Scipy

本文总结了Anacoda和Jupyter中的Pandas绘图与Scipy重点知识,包括Pandas的线形图、柱状图、直方图、散布图的绘制,并详细介绍了Scipy的矩阵运算、信号处理、图像处理等功能,特别是如何利用快速傅里叶变换进行图像去噪和滤波操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Anacoda&Jupyter DAY 05 重点知识总结 Pandas绘图&Scipy

一 pandas绘图

Series 和 DataFrame 都有一个用于生成各类图标的plot方法 默认情况下 他们都是线型图

import numpy as np
import pandas as pd
from pandas import Series,DataFrame

import matplotlib.pylot as plt

一 线形图
  1. 二维折线图
    s = Series(data = np.random.randint(1,7,size = (10,)),index = np.arange(1,10,2))
    s.plot()在这里插入图片描述

  2. DataFrame 折线图
    data = np.random.randint(0,100,size = (5,5))
    index = [‘first’,‘second’,‘third’,‘fourth’,‘fifth’]
    columns = [‘jack’,‘rose’,‘bob’,‘lucy’,‘lily’]

    df = DataFrame(data = data , index =index,columns = columns)
    df.plot()在这里插入图片描述

二 柱状图

柱状图示例 kind = ‘bar’/‘barh’
kind = ‘bar’ 是纵向的柱状图
kind = ‘barh’ 是横向的柱状图

  1. Series 柱状图示例
    s = Series(data = [100,200,30],index = [‘lucy’,‘lily’,‘jack’])
    s.plot(kind = ‘bar’)
    在这里插入图片描述
    s.plot(kind = ‘barh’)
    在这里插入图片描述

  2. DataFrame柱状图示例
    data = np.random.randint(0,100,size = (4,3))
    index = list(‘ABCD’)
    columns = [‘python’,‘C’,‘java’]

    df = DataFrame(data = data,index = index,columns = columns)
    df.plot(kind = ‘bar’)
    在这里插入图片描述

三 直方图
  1. 调用hist方法
    柱高表示数据的频数 主款表示各组数据的组数
    参数bins可以设置直方图方柱个数上线 越大柱宽越小 数据分组越精细
    设置density = True 可以将频数转换为概率
    s = Series(data = [1,2,2,1,3,3,5,8,4,9,6,4,1,2])
    s.plot(kind = ‘hist’,bins = 50) ## bins 是组数 就是在这个区间内 一共分多少组 比如分成三组 那么会计算1-3之间的数的频数
    在这里插入图片描述
  2. kde图 : 核密度估计 用于弥补直方图中由于参数bins设置不合理导致的精度缺失的问题
    s.plot(kind= ‘hist’,density = True,bins = 5) # 设置density参数为True,可以把频数转换为概率
    s.plot(kind= ‘kde’)
    在这里插入图片描述
四 散布图

散步图是观察两个以为数据数列之间的关系的有效方法 DataFrame对象可用
使用方法 kind = ‘scatter’ 给明标签 columns

  1. data = np.random.normal(size = (1000,2))
    columns = list(‘AB’)
    df = DataFrame(data = data,columns = columns)
    df.plot(kind = ‘scatter’,x = ‘A’,y = ‘B’)

在这里插入图片描述

二 Scipy

Scipy 依赖于Numpy
Scipy 提供了真正的矩阵
Scipy 包含的功能 : 最优化 线性代数 积分 插值 拟合 特殊函数 快速傅里叶变化 信号处理 图像处理 常微分方程
Scipy是高端科学计算工具包
Scipy由一些特定的子模块构成
在这里插入图片描述

  1. 利用快速傅里叶变换图片消噪
import scipy.fftpack as fftpack
import matplotlib.pyplot as plt

data = plt.imread('moonlanding.png')
data2 = fftpack.fft2(data)
data3 
03-09
### Anaconda Python Distribution Installation and Usage #### Installing Anaconda For installing Anaconda, it is recommended to download from a reliable source such as the Tsinghua University mirror site[^3]. This ensures faster downloads and stable versions of Anaconda. Once downloaded, follow the installation instructions provided by the installer. During installation, users can choose whether to add Anaconda's Python to the system PATH environment variable or not. It is generally advised against adding Anaconda to the PATH during installation unless specifically required, to avoid conflicts with other Python installations on the same machine. #### Setting Up Jupyter Notebook in Specific Conda Environments To utilize Jupyter Notebook within a specific conda environment, ensure that Jupyter Notebook gets installed inside this designated environment[^1]. After activating the desired conda environment using `conda activate myenv`, where `myenv` represents your chosen environment name, proceed to install Jupyter via `conda install jupyter`. Once completed, launching Jupyter will be confined to utilizing only packages available within this particular conda environment. #### Managing Packages Using Pip Within Anaconda Environment Since version 2.7.9 of Python, pip has been integrated into the core Python setup[^2], making package management more streamlined even when working under an Anaconda distribution context. Users may leverage both `conda` commands alongside `pip` for managing libraries; however, preference should always lean towards using `conda` first due to better integration with Anaconda environments. ```bash # Example command sequence for setting up a new project-specific anaconda env conda create --name myproject python=3.8 conda activate myproject conda install numpy pandas matplotlib seaborn scikit-learn jupyter ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值