0

I am trying to plot the following data frame. X and Y are lists. After I prepare those lists I construct the data frame via dictionary. But when I plot it doesn't actually plot.

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

And my data looks like this (both before melt and after melt)

      MAP@k       day    ndcg@k
0  0.201919  20150203  0.245559
1  0.198214  20150204  0.241085

        day variable     value
0  20150203   ndcg@k  0.245559
1  20150204   ndcg@k  0.241085
2  20150203    MAP@k  0.201919
3  20150204    MAP@k  0.198214

1 Answer 1

2

It is working for me. Try following

import pandas as pd
from  ggplot import *

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

df2 = pd.melt(df[['day', 'ndcg@k', 'MAP@k']], 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

Sign up to request clarification or add additional context in comments.

3 Comments

I think it was some strange thing. kill the shell and re ran happened to work. But how can I get the actual dates
I strip the date and then later did the following: df['day'] = pd.to_datetime(df['day']) but didn't get the actual dates to show up
There is absolutely no plotting for me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.