# -*- coding: utf-8 -*-
"""
Created on Fri May 24 10:40:55 2019
@author: User
"""
import pandas as pd
import numpy as np
dates=[pd.Timestamp('2018-05-05'),pd.Timestamp('2018-05-06'),pd.Timestamp('2018-05-07')]
ts=pd.Series(np.random.randn(3),dates)
print(ts)
print(ts.index)
print(type(ts.index))
print("\n pd.date_range('2018-05-01','2018-05-10') 实现日期索引:")
dates=pd.date_range('2018-05-01','2018-05-10')
tsdr=pd.Series(np.random.randn(10),dates)
print(tsdr)
print("\n pd.Period('2018-05-05') 实现日期索引:")
dates=[pd.Period('2018-05-05'),pd.Period('2018-05-06'),pd.Period('2018-05-07')]
tsp=pd.Series(np.random.randn(3),dates)
print(tsp)
运行:
# -*- coding: utf-8 -*-
"""
Created on Fri May 24 10:40:55 2019
@author: User
"""
import pandas as pd
import numpy as np
dates=[pd.Timestamp('2018-05-05'),pd.Timestamp('2018-05-06'),pd.Timestamp('2018-05-07')]
ts=pd.Series(np.random.randn(3),dates)
print(ts)
print(ts.index)
print(type(ts.index))
print("\n pd.date_range('2018-05-01','2018-05-10') 实现日期索引:")
dates=pd.date_range('2018-05-01','2018-05-10')
tsdr=pd.Series(np.random.randn(10),dates)
print(tsdr)
print("\n pd.Period('2018-05-05') 实现日期索引:")
dates=[pd.Period('2018-05-05'),pd.Period('2018-05-06'),pd.Period('2018-05-07')]
tsp=pd.Series(np.random.randn(3),dates)
print(tsp)