Python是進行數據分析的一種出色語言,主要是因為以數據為中心的python軟件包具有奇妙的生態係統。 Pandas是其中的一種,使導入和分析數據更加容易。
Pandas 係列是帶有軸標簽的一維ndarray。標簽不必是唯一的,但必須是可哈希的類型。該對象同時支持基於整數和基於標簽的索引,並提供了許多方法來執行涉及索引的操作。
Pandas Series.dtype
屬性返回給定Series對象的基礎數據的數據類型。
用法: Series.dtype
參數:沒有
返回:數據類型
範例1:采用Series.dtype
屬性,以查找給定Series對象的基礎數據的數據類型。
# importing pandas as pd
import pandas as pd
# Creating the Series
sr = pd.Series(['New York', 'Chicago', 'Toronto', 'Lisbon'])
# Creating the row axis labels
sr.index = ['City 1', 'City 2', 'City 3', 'City 4']
# Print the series
print(sr)
輸出:
現在我們將使用Series.dtype
屬性以查找給定Series對象的數據類型。
# return the data type
sr.dtype
輸出:
正如我們在輸出中看到的,Series.dtype
屬性返回了“ O”,表示基礎數據的數據類型是對象類型。
範例2:采用Series.dtype
屬性,以查找給定Series對象的基礎數據的數據類型。
# importing pandas as pd
import pandas as pd
# Creating the Series
sr = pd.Series([1000, 5000, 1500, 8222])
# Print the series
print(sr)
輸出:
現在我們將使用Series.dtype
屬性以查找給定Series對象的數據類型。
# return the data type
sr.dtype
輸出:
正如我們在輸出中看到的,Series.dtype
屬性已返回“ int64”,表示基礎數據的數據類型為int64
類型。
相關用法
- Python pandas.map()用法及代碼示例
- Python Pandas Timestamp.now用法及代碼示例
- Python Pandas Timestamp.second用法及代碼示例
- Python Pandas DataFrame.abs()用法及代碼示例
- Python Pandas Series.lt()用法及代碼示例
- Python Pandas dataframe.all()用法及代碼示例
- Python Pandas DataFrame.ix[ ]用法及代碼示例
- Python Pandas Series.pop()用法及代碼示例
- Python Pandas TimedeltaIndex.max用法及代碼示例
- Python Pandas Timestamp.dst用法及代碼示例
- Python Pandas Timestamp.tz用法及代碼示例
- Python Pandas Series.mean()用法及代碼示例
- Python Pandas TimedeltaIndex.min用法及代碼示例
- Python Pandas Series.ptp()用法及代碼示例
- Python Pandas dataframe.cov()用法及代碼示例
注:本文由純淨天空篩選整理自Shubham__Ranjan大神的英文原創作品 Python | Pandas Series.dtype。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。