import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

from convert_to_timeseries import convert_data_to_timeseries

# Input file containing data
input_file = 'data_timeseries.txt'

# Load data
data1 = convert_data_to_timeseries(input_file, 2)
data2 = convert_data_to_timeseries(input_file, 3)
dataframe = pd.DataFrame({'first': data1, 'second': data2})

# Print max and min
print '\nMaximum:\n', dataframe.max()
print '\nMinimum:\n', dataframe.min()

# Print mean
print '\nMean:\n', dataframe.mean()
print '\nMean row-wise:\n', dataframe.mean(1)[:10]

# Plot rolling mean
pd.rolling_mean(dataframe, window=24).plot()

# Print correlation coefficients
print '\nCorrelation coefficients:\n', dataframe.corr()

# Plot rolling correlation
plt.figure()
pd.rolling_corr(dataframe['first'], dataframe['second'], window=60).plot()
예제 #2
0
# ^_^ coding:utf-8 ^_^

import numpy as np 
import pandas as pd 
import matplotlib.pyplot as plt 

from convert_to_timeseries import convert_data_to_timeseries

# 输入数据文件
input_file = 'data_timeseries.txt'

# 加载输入数据
column_num = 2
data_timeseries = convert_data_to_timeseries(input_file, column_num)

# 确定画图起止年份
start = '2008'
end = '2015'

# 画出给定年份范围内数据
plt.figure()
data_timeseries[start:end].plot()
plt.title('Data from {} to {}'.format(start, end))
plt.show()

# 确定画图起止年月
start = '2007-2'
end = '2017-11'

# 画出给定年月范围内数据
plt.figure()
예제 #3
0
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

from convert_to_timeseries import convert_data_to_timeseries

# Input file containing data
input_file = 'data_timeseries.txt'

# Load data
data1 = convert_data_to_timeseries(input_file,
                                   2)  ####column 2 is called the 'first'
data2 = convert_data_to_timeseries(input_file,
                                   3)  ####and column 3 is called the 'second'
dataframe = pd.DataFrame({'first': data1, 'second': data2})

print(dataframe)

# Plot data
dataframe['1952':'1955'].plot()
plt.title('Data overlapped on top of each other')

# Plot the difference
plt.figure()
difference = dataframe['1952':'1955']['first'] - dataframe['1952':'1955'][
    'second']
difference.plot()
plt.title('Difference (first - second)')

# When 'first' is greater than a certain threshold
# and 'second' is smaller than a certain threshold
예제 #4
0
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

from convert_to_timeseries import convert_data_to_timeseries

# Input file containing data
input_file = 'data_timeseries.txt'

# Load data
column_num = 2
data_timeseries = convert_data_to_timeseries(input_file, column_num)

# Plot within a certain year range
start = '2008'
end = '2015'
plt.figure()
data_timeseries[start:end].plot()
plt.title('Data from ' + start + ' to ' + end)

# Plot within a certain range of dates
start = '2007-2'
end = '2007-11'
plt.figure()
data_timeseries[start:end].plot()
plt.title('Data from ' + start + ' to ' + end)

plt.show()