最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

pandas如何使用列表和字典創(chuàng)建?Series

 更新時(shí)間:2021年12月21日 08:33:21   作者:遲業(yè)  
這篇文章主要介紹了pandas如何使用列表和字典創(chuàng)建?Series,pandas 是基于NumPy的一種工具,該工具是為解決數(shù)據(jù)分析任務(wù)而創(chuàng)建的,下文我們就來看看文章是怎樣介紹pandas,需要的朋友也可以參考一下

前言:

Pandas 納入了大量庫和一些標(biāo)準(zhǔn)的數(shù)據(jù)模型,提供了高效地操作大型數(shù)據(jù)集所需的工具。pandas提供了大量能使我們快速便捷地處理數(shù)據(jù)的函數(shù)和方法。

為了讓大家對(duì)pandas的操作更加熟練,我整理了一些關(guān)于pandas的小操作,會(huì)依次為大家展示

今天我將先為大家如何關(guān)于pandas如何使用列表和字典創(chuàng)建 Series。

01 使用列表創(chuàng)建 Series

import pandas as pd
 
ser1 = pd.Series([1.5, 2.5, 3, 4.5, 5.0, 6])
print(ser1)


Output:

0??? 1.5
1??? 2.5
2??? 3.0
3??? 4.5
4??? 5.0
5??? 6.0
dtype: float64

02 使用 name 參數(shù)創(chuàng)建 Series

import pandas as pd
 
ser2 = pd.Series(["India", "Canada", "Germany"], name="Countries")
print(ser2)


Output:

0????? India
1???? Canada
2??? Germany
Name: Countries, dtype: object

03 使用簡寫的列表創(chuàng)建 Series

import pandas as pd
 
ser3 = pd.Series(["A"]*4)
print(ser3)


Output:

0??? A
1??? A
2??? A
3??? A
dtype: object

04 使用字典創(chuàng)建 Series

import pandas as pd
 
ser4 = pd.Series({"India": "New Delhi",
                  "Japan": "Tokyo",
                  "UK": "London"})
print(ser4)


Output:

India??? New Delhi
Japan??????? Tokyo
UK????????? London
dtype: object

05 如何使用 Numpy 函數(shù)創(chuàng)建 Series

import pandas as pd
import numpy as np
 
ser1 = pd.Series(np.linspace(1, 10, 5))
print(ser1)
 
ser2 = pd.Series(np.random.normal(size=5))
print(ser2)


Output:

0???? 1.00
1???? 3.25
2???? 5.50
3???? 7.75
4??? 10.00
dtype: float64
0?? -1.694452
1?? -1.570006
2??? 1.713794
3??? 0.338292
4??? 0.803511
dtype: float64

06 如何獲取 Series 的索引和值

import pandas as pd
import numpy as np
 
ser1 = pd.Series({"India": "New Delhi",
                  "Japan": "Tokyo",
                  "UK": "London"})
 
print(ser1.values)
print(ser1.index)
 
print("\n")
 
ser2 = pd.Series(np.random.normal(size=5))
print(ser2.index)
print(ser2.values)


Output:

['New Delhi' 'Tokyo' 'London']
Index(['India', 'Japan', 'UK'], dtype='object')
?
?
RangeIndex(start=0, stop=5, step=1)
[ 0.66265478 -0.72222211? 0.3608642?? 1.40955436? 1.3096732 ]

07 如何在創(chuàng)建 Series 時(shí)指定索引

import pandas as pd
 
values = ["India", "Canada", "Australia",
          "Japan", "Germany", "France"]
 
code = ["IND", "CAN", "AUS", "JAP", "GER", "FRA"]
 
ser1 = pd.Series(values, index=code)
 
print(ser1)


Output:

IND??????? India
CAN?????? Canada
AUS??? Australia
JAP??????? Japan
GER????? Germany
FRA?????? France
dtype: object

08?如何獲取 Series 的大小和形狀

import pandas as pd
 
values = ["India", "Canada", "Australia",
          "Japan", "Germany", "France"]
 
code = ["IND", "CAN", "AUS", "JAP", "GER", "FRA"]
 
ser1 = pd.Series(values, index=code)
 
print(len(ser1))
 
print(ser1.shape)
 
print(ser1.size)


Output:

6
(6,)
6

09 如何獲取 Series 開始或末尾幾行數(shù)據(jù)

Head()函數(shù):

import pandas as pd
 
values = ["India", "Canada", "Australia",
          "Japan", "Germany", "France"]
 
code = ["IND", "CAN", "AUS", "JAP", "GER", "FRA"]
 
ser1 = pd.Series(values, index=code)
 
print("-----Head()-----")
print(ser1.head())
 
print("\n\n-----Head(2)-----")
print(ser1.head(2))


Output:

-----Head()-----
IND??????? India
CAN?????? Canada
AUS??? Australia
JAP??????? Japan
GER????? Germany
dtype: object
?
?
-----Head(2)-----
IND???? India
CAN??? Canada
dtype: object

Tail()函數(shù):

import pandas as pd
 
values = ["India", "Canada", "Australia",
          "Japan", "Germany", "France"]
 
code = ["IND", "CAN", "AUS", "JAP", "GER", "FRA"]
 
ser1 = pd.Series(values, index=code)
 
print("-----Tail()-----")
print(ser1.tail())
 
print("\n\n-----Tail(2)-----")
print(ser1.tail(2))


Output:

-----Tail()-----
CAN?????? Canada
AUS??? Australia
JAP??????? Japan
GER????? Germany
FRA?????? France
dtype: object
?
?
-----Tail(2)-----
GER??? Germany
FRA???? France
dtype: object

Take()函數(shù):

import pandas as pd
 
values = ["India", "Canada", "Australia",
          "Japan", "Germany", "France"]
 
code = ["IND", "CAN", "AUS", "JAP", "GER", "FRA"]
 
ser1 = pd.Series(values, index=code)
 
print("-----Take()-----")
print(ser1.take([2, 4, 5]))


Output:

-----Take()-----
AUS??? Australia
GER????? Germany
FRA?????? France
dtype: object

10 使用切片獲取 Series 子集

import pandas as pd
 
num = [000, 100, 200, 300, 400, 500, 600, 700, 800, 900]
 
idx = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J']
 
series = pd.Series(num, index=idx)
 
print("\n [2:2] \n")
print(series[2:4])
 
print("\n [1:6:2] \n")
print(series[1:6:2])
 
print("\n [:6] \n")
print(series[:6])
 
print("\n [4:] \n")
print(series[4:])
 
print("\n [:4:2] \n")
print(series[:4:2])
 
print("\n [4::2] \n")
print(series[4::2])
 
print("\n [::-1] \n")
print(series[::-1])


Output:

?[2:2]
?
C??? 200
D??? 300
dtype: int64
?
?[1:6:2]
?
B??? 100
D??? 300
F??? 500
dtype: int64
?
?[:6]
?
A????? 0
B??? 100
C??? 200
D??? 300
E??? 400
F??? 500
dtype: int64
?
?[4:]
?
E??? 400
F??? 500
G??? 600
H??? 700
I??? 800
J??? 900
dtype: int64
?
?[:4:2]
?
A????? 0
C??? 200
dtype: int64
?
?[4::2]
?
E??? 400
G??? 600
I??? 800
dtype: int64
?
?[::-1]
?
J??? 900
I??? 800
H??? 700
G??? 600
F??? 500
E??? 400
D??? 300
C??? 200
B??? 100
A????? 0
dtype: int64

到此這篇關(guān)于pandas如何使用列表和字典創(chuàng)建 Series的文章就介紹到這了,更多相關(guān)pandas使用列表和字典創(chuàng)建 Series內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Pandas數(shù)據(jù)集的分塊讀取的實(shí)現(xiàn)

    Pandas數(shù)據(jù)集的分塊讀取的實(shí)現(xiàn)

    本文主要介紹了Pandas數(shù)據(jù)集的分塊讀取的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2022-08-08
  • openCV實(shí)現(xiàn)圖像融合的示例代碼

    openCV實(shí)現(xiàn)圖像融合的示例代碼

    圖像融合是兩幅圖片疊加在一起,本文主要介紹了openCV實(shí)現(xiàn)圖像融合的示例代碼,文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-03-03
  • Python學(xué)習(xí)之不同數(shù)據(jù)類型間的轉(zhuǎn)換總結(jié)

    Python學(xué)習(xí)之不同數(shù)據(jù)類型間的轉(zhuǎn)換總結(jié)

    類型轉(zhuǎn)換,就是將自身的數(shù)據(jù)類型變成新的數(shù)據(jù)類型,并擁有新的數(shù)據(jù)類型的所有功能的過程。本文將詳細(xì)為大家介紹如何在Python中實(shí)現(xiàn)不同數(shù)據(jù)類型的轉(zhuǎn)換,感興趣的可以了解一下
    2022-03-03
  • 詳解Python開發(fā)中如何使用Hook技巧

    詳解Python開發(fā)中如何使用Hook技巧

    這篇文章主要介紹了詳解Python開發(fā)中如何使用Hook技巧,詳細(xì)的介紹了Python Hook的用法和示例,有興趣的可以了解一下
    2017-11-11
  • Python Beautiful Soup 使用示例詳解

    Python Beautiful Soup 使用示例詳解

    Beautiful Soup 是一個(gè) Python 庫,用于解析 HTML 和 XML 文檔,并提供簡單而直觀的 API 來遍歷文檔樹、搜索元素、提取內(nèi)容等,這篇文章主要介紹了Python Beautiful Soup 使用示例詳解,需要的朋友可以參考下
    2024-05-05
  • 詳解OpenCV實(shí)現(xiàn)特征提取的方法

    詳解OpenCV實(shí)現(xiàn)特征提取的方法

    在本文中,我們將一起探索幾種從圖像中提取顏色、形狀和紋理特征的方法,這些方法基于處理圖像的經(jīng)驗(yàn),感興趣的小伙伴可以了解一下
    2022-05-05
  • 分享一下Python數(shù)據(jù)分析常用的8款工具

    分享一下Python數(shù)據(jù)分析常用的8款工具

    Python是數(shù)據(jù)處理常用工具,可以處理數(shù)量級(jí)從幾K至幾T不等的數(shù)據(jù),具有較高的開發(fā)效率和可維護(hù)性,還具有較強(qiáng)的通用性和跨平臺(tái)性,這里就為大家分享幾個(gè)不錯(cuò)的數(shù)據(jù)分析工具,需要的朋友可以參考下
    2018-04-04
  • 基于pytorch實(shí)現(xiàn)運(yùn)動(dòng)鞋品牌識(shí)別功能

    基于pytorch實(shí)現(xiàn)運(yùn)動(dòng)鞋品牌識(shí)別功能

    這篇文章主要給大家介紹了關(guān)于如何基于pytorch實(shí)現(xiàn)運(yùn)動(dòng)鞋品牌識(shí)別功能,文中通過圖文以及實(shí)例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用PyTorch具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2024-02-02
  • Python中操作MySQL入門實(shí)例

    Python中操作MySQL入門實(shí)例

    這篇文章主要介紹了Python中操作MySQL入門實(shí)例,本文講解了安裝、打開數(shù)據(jù)庫連接、插入數(shù)據(jù)、查詢數(shù)據(jù)、刪除數(shù)據(jù)等操作,需要的朋友可以參考下
    2015-02-02
  • 理解python多線程(python多線程簡明教程)

    理解python多線程(python多線程簡明教程)

    這篇文章主要介紹了理解python多線程,一個(gè)快速理解python多線程的簡明教程,需要的朋友可以參考下
    2014-06-06

最新評(píng)論

临猗县| 赤水市| 富平县| 满城县| 浦北县| 馆陶县| 项城市| 西吉县| 遂宁市| 晋江市| 河池市| 阳信县| 河曲县| 宣恩县| 天津市| 宜川县| 吴堡县| 琼中| 贵定县| 东海县| 修武县| 根河市| 资阳市| 潼关县| 宁都县| 七台河市| 玉门市| 准格尔旗| 闻喜县| 绥芬河市| 崇文区| 鄂尔多斯市| 张北县| 平陆县| 元阳县| 皋兰县| 茶陵县| 榆社县| 延边| 静乐县| 定安县|