{"id":1316,"date":"2023-03-25T10:12:45","date_gmt":"2023-03-25T02:12:45","guid":{"rendered":""},"modified":"2023-03-25T10:12:45","modified_gmt":"2023-03-25T02:12:45","slug":"\u5206\u6790\u65f6\u95f4\u5e8f\u5217\u6570\u636e","status":"publish","type":"post","link":"https:\/\/bianchenghao6.com\/1316.html","title":{"rendered":"\u5206\u6790\u65f6\u95f4\u5e8f\u5217\u6570\u636e"},"content":{"rendered":"
\n
\u5206\u6790\u65f6\u95f4\u5e8f\u5217\u6570\u636e\u8be6\u7ec6\u64cd\u4f5c\u6559\u7a0b<\/span>\n <\/div>\n \u4f7f\u7528pd.date_range\u5305\u521b\u5efa\u4e00\u7cfb\u5217\u65e5\u671f<\/span>\u65f6\u95f4\u5e8f\u5217\u6570\u636e\u4ecb\u7ecd<\/h2>\n
\n <\/div>\n
\u5b89\u88c5\u6709\u7528\u7684\u5305<\/h2>\n
\n https:\/\/www.lidihuo.com\/pandas\/pandas-index.html\n <\/div>\n # Filename : example.py<\/span>
# Copyright : 2020 By Lidihuo<\/span>
# Author by : www.lidihuo.com<\/span>
# Date : 2020-08-26<\/span>
pip install pandas
<\/span><\/code><\/pre>\n<\/p><\/div>\n # Filename : example.py<\/span>
# Copyright : 2020 By Lidihuo<\/span>
# Author by : www.lidihuo.com<\/span>
# Date : 2020-08-26<\/span>
conda install -c anaconda pandas
<\/span><\/code><\/pre>\n<\/p><\/div>\n # Filename : example.py<\/span>
# Copyright : 2020 By Lidihuo<\/span>
# Author by : www.lidihuo.com<\/span>
# Date : 2020-08-26<\/span>
pip install hmmlearn
<\/span><\/code><\/pre>\n<\/p><\/div>\n # Filename : example.py<\/span>
# Copyright : 2020 By Lidihuo<\/span>
# Author by : www.lidihuo.com<\/span>
# Date : 2020-08-26<\/span>
conda install -c anaconda hmmlearn
<\/span><\/code><\/pre>\n<\/p><\/div>\n # Filename : example.py<\/span>
# Copyright : 2020 By Lidihuo<\/span>
# Author by : www.lidihuo.com<\/span>
# Date : 2020-08-26<\/span>
pip install pystruct
<\/span><\/code><\/pre>\n<\/p><\/div>\n # Filename : example.py<\/span>
# Copyright : 2020 By Lidihuo<\/span>
# Author by : www.lidihuo.com<\/span>
# Date : 2020-08-26<\/span>
pip install cvxopt
<\/span><\/code><\/pre>\n<\/p><\/div>\n # Filename : example.py<\/span>
# Copyright : 2020 By Lidihuo<\/span>
# Author by : www.lidihuo.com<\/span>
# Date : 2020-08-26<\/span>
conda install -c anaconda cvdoxt
<\/span><\/code><\/pre>\n<\/p><\/div>\nPandas:\u4ece\u65f6\u95f4\u5e8f\u5217\u6570\u636e\u4e2d\u5904\u7406\uff0c\u5206\u5272\u548c\u63d0\u53d6\u7edf\u8ba1\u4fe1\u606f<\/h2>\n
\n \u901a\u8fc7\u4f7f\u7528pd.Series\u5305\u5bf9\u5e26\u6709\u65e5\u671f\u6570\u636e\u8fdb\u884c\u7d22\u5f15<\/span>
\n \u4f7f\u7528ts.resample\u5305\u6267\u884c\u91cd\u65b0\u91c7\u6837<\/span>
\n \u6539\u53d8\u9891\u7387<\/span> <\/p>\n # Filename : example.py<\/span>
# Copyright : 2020 By Lidihuo<\/span>
# Author by : www.lidihuo.com<\/span>
# Date : 2020-08-26<\/span>
import <\/span>numpy as <\/span>np
import <\/span>matplotlib.pyplot as <\/span>plt
import <\/span>pandas <\/span>as <\/span>pd
<\/span><\/code><\/pre>\n<\/p><\/div>\n # Filename : example.py<\/span>
# Copyright : 2020 By Lidihuo<\/span>
# Author by : www.lidihuo.com<\/span>
# Date : 2020-08-26<\/span>
def <\/span>read_data(input_file):
input_data = np.loadtxt<\/span>(input_file, delimiter = None)
<\/span><\/code><\/pre>\n<\/p><\/div>\n # Filename : example.py<\/span>
# Copyright : 2020 By Lidihuo<\/span>
# Author by : www.lidihuo.com<\/span>
# Date : 2020-08-26<\/span>
dates = pd.date_range<\/span>('1950-01'<\/span>, periods = input_data.shape[0], freq = 'M'<\/span>)
<\/span><\/code><\/pre>\n<\/p><\/div>\n # Filename : example.py<\/span>
# Copyright : 2020 By Lidihuo<\/span>
# Author by : www.lidihuo.com<\/span>
# Date : 2020-08-26<\/span>
output = pd.Series<\/span>(input_data[:, index], index = dates)
return <\/span>output
if <\/span>__name__=='__main__'<\/span>:
<\/span><\/code><\/pre>\n<\/p><\/div>\n # Filename : example.py<\/span>
# Copyright : 2020 By Lidihuo<\/span>
# Author by : www.lidihuo.com<\/span>
# Date : 2020-08-26<\/span>
input_file = \"\/Users\/admin\/AO.txt\"<\/span>
<\/span><\/code><\/pre>\n<\/p><\/div>\n # Filename : example.py<\/span>
# Copyright : 2020 By Lidihuo<\/span>
# Author by : www.lidihuo.com<\/span>
# Date : 2020-08-26<\/span>
timeseries = read_data(input_file)
<\/span><\/code><\/pre>\n<\/p><\/div>\n # Filename : example.py<\/span>
# Copyright : 2020 By Lidihuo<\/span>
# Author by : www.lidihuo.com<\/span>
# Date : 2020-08-26<\/span>
plt.figure<\/span>()
timeseries.plot<\/span>()
plt.show<\/span>()
<\/span><\/code><\/pre>\n<\/p><\/div>\n\n <\/div>\n
\n <\/div>\n
# Filename : example.py<\/span>
# Copyright : 2020 By Lidihuo<\/span>
# Author by : www.lidihuo.com<\/span>
# Date : 2020-08-26<\/span>
timeseries['1980'<\/span>:'1990'<\/span>].plot<\/span>()
<matplotlib.axes._subplots.AxesSubplot at 0xa0e4b00>
plt.show<\/span>()
<\/span><\/code><\/pre>\n<\/p><\/div>\n\n <\/div>\n
\u4ece\u65f6\u95f4\u5e8f\u5217\u6570\u636e\u4e2d\u63d0\u53d6\u7edf\u8ba1\u4fe1\u606f<\/h2>\n
# Filename : example.py<\/span>
# Copyright : 2020 By Lidihuo<\/span>
# Author by : www.lidihuo.com<\/span>
# Date : 2020-08-26<\/span>
timeseries.mean<\/span>()
<\/span><\/code><\/pre>\n<\/p><\/div>\n # Filename : example.py<\/span>
# Copyright : 2020 By Lidihuo<\/span>
# Author by : www.lidihuo.com<\/span>
# Date : 2020-08-26<\/span>
-0.11143128165238671
<\/span><\/code><\/pre>\n<\/p><\/div>\n # Filename : example.py<\/span>
# Copyright : 2020 By Lidihuo<\/span>
# Author by : www.lidihuo.com<\/span>
# Date : 2020-08-26<\/span>
timeseries.max<\/span>()
<\/span><\/code><\/pre>\n<\/p><\/div>\n # Filename : example.py<\/span>
# Copyright : 2020 By Lidihuo<\/span>
# Author by : www.lidihuo.com<\/span>
# Date : 2020-08-26<\/span>
3.4952999999999999
<\/span><\/code><\/pre>\n<\/p><\/div>\n