2015-03-19 96 views
0

我想繪製下面的數據框。 X和Y是列表。在我準備這些列表之後,我通過字典構造數據框。但是當我把它繪製出來時,並不是真正的情節。Python的ggplot不繪製數據幀

df = pd.DataFrame({"day": day, "[email protected]": x, "[email protected]": y}) 
df2 = pd.melt(df[['day', '[email protected]', '[email protected]']], id_vars=['day']) 
ggplot(aes(x='day', y='value', group='variable', shape='variable', colour='variable'), data=df2) + geom_line() + geom_point() 

我的數據是這樣的(包括熔體之前和之後的熔體)

 [email protected]  day [email protected] 
0 0.201919 20150203 0.245559 
1 0.198214 20150204 0.241085 

     day variable  value 
0 20150203 [email protected] 0.245559 
1 20150204 [email protected] 0.241085 
2 20150203 [email protected] 0.201919 
3 20150204 [email protected] 0.198214 

回答

2

這是爲我工作。嘗試以下

import pandas as pd 
from ggplot import * 

df = pd.DataFrame([{"day": 20150203, "[email protected]": 0.245559, "[email protected]": 0.201919}, 
        {"day": 20150204, "[email protected]": 0.255559, "[email protected]": 0.191919}, 
        {"day": 20150205, "[email protected]": 0.2645559, "[email protected]": 0.181919}, 
        {"day": 20150203, "[email protected]": 0.275559, "[email protected]": 0.171919}, 
        {"day": 20150204, "[email protected]": 0.285559, "[email protected]": 0.161919}, 
        {"day": 20150205, "[email protected]": 0.295559, "[email protected]": 0.151919}]) 

df2 = pd.melt(df[['day', '[email protected]', '[email protected]']], id_vars=['day']) 
df2.day = pd.to_datetime(df2.day, format = '%Y%m%d') 
ggplot(aes(x='day', y='value', group='variable', shape='variable', colour='variable'), data=df2) + geom_line() + geom_point() + scale_x_date(labels = date_format('%Y-%m-%d %H:%M')) 

enter image description here

+0

我認爲這是一些奇怪的事情。殺死殼並重新運行恰好工作。但我怎樣才能得到實際日期 – 2015-03-19 09:29:00

+0

我刪除日期,然後做了以下事情:'df ['day'] = pd.to_datetime(df ['day'])'但沒有得到實際日期顯示up – 2015-03-19 09:30:06

+0

添加日期相關代碼現在查詢... – vrajs5 2015-03-19 09:35:22