Python是進行數據分析的一種出色語言,主要是因為以數據為中心的python軟件包具有奇妙的生態係統。 Pandas是其中的一種,使導入和分析數據更加容易。
Pandas DatetimeIndex.month
屬性輸出一個Index對象,其中包含與DatetimeIndex對象中的每個條目相對應的數值。它輸出的月份為1月= 1,12月= 12,以及之間的每個月對應的數值。
用法: DatetimeIndex.month
返回:包含月份的索引。
範例1:采用DatetimeIndex.month
屬性以查找DatetimeIndex中存在的月份。
# importing pandas as pd
import pandas as pd
# Create the DatetimeIndex
# Here the 'B' represents Business day frequency
didx = pd.DatetimeIndex(start ='2014-08-01 10:00', freq ='B',
periods = 5, tz ='Asia/Calcutta')
# Print the DatetimeIndex
print(didx)
輸出:
現在,我們要查找DatetimeIndex對象中存在的所有月份值。
# find all the months in the object
didx.month
輸出:
從輸出中可以看到,該函數返回了一個Index對象,其中包含與DatetimeIndex對象中每個條目的月份相對應的數值。
範例2:采用DatetimeIndex.month
屬性以查找DatetimeIndex中存在的月份。
# importing pandas as pd
import pandas as pd
# Create the DatetimeIndex
# Here the 'M' represents Month end frequency
didx = pd.DatetimeIndex(start ='2014-08-01 10:00', freq ='M',
periods = 5, tz ='Asia/Calcutta')
# Print the DatetimeIndex
print(didx)
輸出:
現在,我們要查找DatetimeIndex對象中存在的所有月份值。
# find all the months in the object
didx.month
輸出:
從輸出中可以看到,該函數返回了一個Index對象,其中包含與DatetimeIndex對象中每個條目的月份相對應的數值。
相關用法
- 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 DatetimeIndex.month。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。