首页 > 解决方案 > 如何找到时间序列数据之间的相关性并在python中绘制图表

问题描述

我有以下数据:

String  Value   datetime
hello   10  10/3/2017 0:00
hello   45  10/4/2017 0:00
hello   544 10/5/2017 0:00
hello   677 10/6/2017 0:00
hello   899 10/7/2017 0:00
hello   67  10/8/2017 0:00
hello   88  10/9/2017 0:00
hello   77  10/10/2017 0:00
Hi  55  10/3/2017 0:00
Hi  99  10/4/2017 0:00
Hi  33  10/5/2017 0:00
Hi  22  10/6/2017 0:00
Plant   11  10/3/2017 0:00
Plant   44  10/4/2017 0:00
Plant   55  10/5/2017 0:00
Plant   661 10/6/2017 0:00

我想找到字符串值之间的相关性并用这三列绘制折线图,​​我正在使用以下代码:

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

df = pd.read_excel(r'test.xlsx')
df.head()
##to find the correlation between string and the value
s_corr = df.String.str.get_dummies(sep=' ').corrwith(df.Value)
print (s_corr)
#Plot the graph
df.set_index('datetime', inplace=True)
df.plot()

但是当我绘制图表时,图表是用日期时间和值绘制的,但我想用三列绘制。怎么做?

标签: python-3.xpandaspearson-correlation

解决方案


推荐阅读