偷偷摘套内射激情视频,久久精品99国产国产精,中文字幕无线乱码人妻,中文在线中文a,性爽19p

Python 數(shù)據(jù)分析:初識 Pandas

開發(fā) 數(shù)據(jù)分析
本文我們了解了Pandas擴展包的安裝、導(dǎo)入,以及創(chuàng)建Series、DataFrame格式數(shù)據(jù)(后面會詳細(xì)講這兩種格式)。

Python作為一個腳本語言,其廣泛的擴展包生態(tài),使得我們可以利用Python完成幾乎所有的數(shù)據(jù)分析。也就是說,在我們辦公場景下,幾乎可以勝任所有的日常工作。利用Python辦公主要是用擴展包完成,其中最著名的當(dāng)屬Pandas,它也是數(shù)據(jù)分析三劍客之一。

1. Pandas是什么?

首先,我們來認(rèn)識一下Pandas。它是一個開源、BSD許可的庫,為Python編程語言提供高性能、易于使用的數(shù)據(jù)結(jié)構(gòu)和數(shù)據(jù)分析工具。

通常我們使用Pandas完成如下工作:

  • 格式化數(shù)據(jù)的讀取、處理與存儲;
  • 數(shù)據(jù)清洗,如空值、異常值的處理;
  • 數(shù)據(jù)處理分析,支持?jǐn)?shù)據(jù)的增刪改查操作、數(shù)據(jù)描述、相關(guān)性分析等;
  • 跨表處理,支持多張表的組合、連接和堆疊等操作;
  • 繪圖,自帶繪圖功能,可以完成散點圖、線圖、柱狀圖等繪圖;

2. 安裝Pandas環(huán)境

安裝pandas非常簡單,只需要在命令提示符窗口執(zhí)行pip install pandas命令即可。

C:\Users\william>pip install pandas -i https://pypi.tuna.tsinghua.edu.cn/simple
Lookingin indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Collectingpandas
Downloadinghttps://pypi.tuna.tsinghua.edu.cn/packages/ab/63/966db1321a0ad55df1d1fe51505d2cdae191b84c907974873817b0a6e849/pandas-2.2.2-cp311-cp311-win_amd64.whl (11.6 MB)
----------------------------------------11.6/11.6 MB 16.4 MB/s eta 0:00:00
Successfully installed pandas-2.2.2

這里加了-i參數(shù),意思是指定包源,也就是從哪個服務(wù)器上搜索并下載,主要是為了提高下載速度,畢竟默認(rèn)是指向國外的服務(wù)器的,速度較慢。

常用的國內(nèi)源:

  • 清華大學(xué):https://pypi.tuna.tsinghua.edu.cn/simple
  • 阿里云:https://mirrors.aliyun.com/pypi/simple
  • 中國科學(xué)技術(shù)大學(xué):https://pypi.mirrors.ustc.edu.cn/simple

3. 第一次使用

第一次使用Pandas需要在使用前導(dǎo)入包,一般我們會起個別名pd,如下:

import pandas as pd

這里給pandas的包起的別名pd,將會在本系列教程中默認(rèn)使用,后面直接使用pd.methodname()實現(xiàn)對于方法的調(diào)用。

下面先來看看Series數(shù)據(jù)的生成,以及描述統(tǒng)計信息查看。

# 利用range()函數(shù)創(chuàng)建元素和索引
>>> s = pd.Series(range(5),index=['r0','r1','r2','r3','r4'])
>>>s   # 可以觀測到S是一個類似字典的結(jié)構(gòu),由索引和值構(gòu)成。
r0    0
r1    1
r2    2
r3    3
r4    4
dtype: int64


# 查看統(tǒng)計描述信息
>>>s.describe()  
count    5.000000
mean     2.000000
std      1.581139
min      0.000000
25%      1.000000
50%      2.000000
75%      3.000000
max      4.000000
dtype: float64

下面再來看看DataFrame數(shù)據(jù)的生成,以及描述統(tǒng)計信息查看。

# 先利用numpy創(chuàng)建一個二維數(shù)組
>>> import numpy as np
>>> array0 = np.arange(12).reshape(3,4)
>>> array0
array([[ 0,  1,  2,  3],
       [ 4,  5,  6,  7],
       [ 8,  9, 10, 11]])


# 創(chuàng)建DataFrame格式數(shù)據(jù),并分別設(shè)置行列索引
>>> df0 = pd.DataFrame(array,
...                    columns=['a','b','c','d'],
...                    index=['r0','r1','r3'])
>>> df0
    a  b   c   d
r0  0123
r1  4567
r3  891011


# 查看統(tǒng)計描述信息
>>> df0.describe()
         a    b     c     d
count  3.03.03.03.0
mean   4.05.06.07.0
std    4.04.04.04.0
min    0.01.02.03.0
25%    2.03.04.05.0
50%    4.05.06.07.0
75%    6.07.08.09.0
max    8.09.010.011.0

4. 小結(jié)

本節(jié)我們了解了Pandas擴展包的安裝、導(dǎo)入,以及創(chuàng)建Series、DataFrame格式數(shù)據(jù)(后面會詳細(xì)講這兩種格式)。并使用describe()方法查看各列的統(tǒng)計描述信息,它可以幫我們觀察每數(shù)據(jù)的聚集、離散程度。

責(zé)任編輯:趙寧寧 來源: Python知識驛站
相關(guān)推薦

2020-06-05 14:29:07

PythonPandas數(shù)據(jù)分析

2025-07-14 07:21:00

Pandas數(shù)據(jù)分析Python

2024-01-09 13:58:22

PandasPython數(shù)據(jù)分析

2017-09-01 09:52:20

PythonPandas數(shù)據(jù)分析

2023-11-21 09:11:31

2022-11-11 11:35:14

2023-01-28 10:09:00

Pandas數(shù)據(jù)分析Python

2019-09-02 15:12:46

Python 開發(fā)數(shù)據(jù)分析

2020-04-21 10:11:03

Python數(shù)據(jù)分析Pandas

2024-04-09 08:47:34

PandasRollingPython

2022-07-08 06:01:37

D-Tale輔助工具

2021-12-24 10:45:19

PandasLambda數(shù)據(jù)分析

2019-11-04 15:00:01

DatatableR語言數(shù)據(jù)科學(xué)

2022-03-24 09:36:28

Pandas數(shù)據(jù)分析代碼

2025-04-02 09:33:01

2023-12-10 14:06:04

數(shù)據(jù)庫pythonduckdb

2023-05-05 18:45:21

Python人工智能機器學(xué)習(xí)

2023-11-15 18:03:11

Python數(shù)據(jù)分析基本工具

2020-08-30 14:29:01

Pandas數(shù)據(jù)分析函數(shù)

2020-03-19 15:11:14

Pandas數(shù)據(jù)分析代碼
點贊
收藏

51CTO技術(shù)棧公眾號