Pandas 係列是帶有軸標簽的一維ndarray。標簽不必是唯一的,但必須是可哈希的類型。該對象同時支持基於整數和基於標簽的索引,並提供了許多方法來執行涉及索引的操作。
Pandas Series.ravel()
函數將展平的基礎數據作為ndarray返回。
用法: Series.ravel(order=’C’)
參數:排序
返回:ndarray
範例1:采用Series.ravel()
函數將給定Series對象的元素作為ndarray返回。
# importing pandas as pd
import pandas as pd
# Creating the Series
sr = pd.Series([10, 25, 3, 11, 24, 6])
# Create the Index
index_ = ['Coca Cola', 'Sprite', 'Coke', 'Fanta', 'Dew', 'ThumbsUp']
# set the index
sr.index = index_
# Print the series
print(sr)
輸出:
現在我們將使用Series.ravel()
函數將給定Series對象的基礎數據作為ndarray返回。
# return an ndarray
result = sr.ravel()
# Print the result
print(result)
輸出:
正如我們在輸出中看到的,Series.ravel()
函數已返回一個ndarray,其中包含給定series對象的數據。
範例2:采用Series.ravel()
函數將給定Series對象的元素作為ndarray返回。
# importing pandas as pd
import pandas as pd
# Creating the Series
sr = pd.Series(['New York', 'Chicago', 'Toronto', 'Lisbon', 'Rio'])
# Create the Index
index_ = ['City 1', 'City 2', 'City 3', 'City 4', 'City 5']
# set the index
sr.index = index_
# Print the series
print(sr)
輸出:
現在我們將使用Series.ravel()
函數將給定Series對象的基礎數據作為ndarray返回。
# return an ndarray
result = sr.ravel()
# Print the result
print(result)
輸出:
正如我們在輸出中看到的,Series.ravel()
函數已返回一個ndarray,其中包含給定series對象的數據。
相關用法
- Python pandas.map()用法及代碼示例
- Python Pandas TimedeltaIndex.max用法及代碼示例
- Python Pandas TimedeltaIndex.min用法及代碼示例
- Python Pandas Series.eq()用法及代碼示例
- Python Pandas Series.ne()用法及代碼示例
- Python Pandas Series.ge()用法及代碼示例
- Python Pandas Series.le()用法及代碼示例
- Python Pandas Series.all()用法及代碼示例
- Python Pandas Series.abs()用法及代碼示例
- Python Pandas DataFrame.ix[ ]用法及代碼示例
- Python Pandas Series.sum()用法及代碼示例
- Python Pandas Series.str.pad()用法及代碼示例
- Python Pandas Series.lt()用法及代碼示例
- Python Pandas Timestamp.day用法及代碼示例
注:本文由純淨天空篩選整理自Shubham__Ranjan大神的英文原創作品 Python | Pandas Series.ravel()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。