## I'm on my way...

# Panda、Numpy、Matplotlib演示

EaborH
2025-03-09 2025-03-09 Created 2025-03-13 15:30:43 2025-03-13 15:30:43 Updated

- 机器学习

- 库

### 1.matplotlib

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12

    import matplotlib
    matplotlib.use('TkAgg')       #使用 `TkAgg`后端
    from matplotlib import pyplot as plt
    x=[1,2,3,4,5]
    y=[2,3,4,5,6]
    fig1 = plt.figure(figsize = (5,5))
    plt.plot(x,y)       #散点 plt.scatter(x, y)
    plt.title('y vs x')
    plt.xlabel('x')
    plt.ylabel('y')
    plt.show()

### 2.numpy

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13

    import numpy as np
    a = np.eye(5)       #对角线数组
    print(type(a))
    print(a)
    b = np.ones((5,5))      #全是1的数组
    print(type(b))
    print(b)
    print(b.shape)      #b数组的维度
    c = a+b
    print(type(c))
    print(c.shape)
    print(c)

### 3.panda

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13

    import pandas as pd
    data = pd.read_csv('detectedData01.csv')
    x = data.loc[:,'编号']        #数据索引
    y = data.loc[:,'姓名']
    c = data.loc[data['性别'] == 1, '姓名']       #筛选列表中性别==1的下姓名`
    #---------------------------------------------------------------------------------------

    data_array = np.array(data)       #调用numpy中arry()方法转换数组

    data_new = data + 10       #所有数据＋10
    data_new.head()       #展示部分数据
    data_new.to_csv('data_new.csv')       #新文件保存

- Title: Panda、Numpy、Matplotlib演示
- Author: EaborH
- Created at : 2025-03-09 00:00:00
- Updated at : 2025-03-13 15:30:43
- Link: https://eabor.xyz/2025/03/09/Panda、Numpy、Matplotlib演示/
- License: This work is licensed under CC BY-NC-SA 4.0.

- #库

面向对象 Prev posts
炎性指标 Next posts