I have the following 2 dataframes posts
, which shows when a particular post was published with the publisher UserId
(A user has made more than 1 post) and badges
,which shows the date-time when a particular user attained a badge, I have shown just a part of them.
I want to create a line plot which would represent the mean of the posts made by users before and after the attainment of the badge(i.e., x-axis should have the days 1 week before and 1 week after attainment of badge and y-axis should have mean number of posts made by users in that duration).
I tried the following code but I am getting AttributeError: 'function' object has no attribute 'line'
. Please provide me a way to fix this.
Code example (dataset generation and function):
import pandas as pd
from matplotlib import pyplot as plt
posts = pd.DataFrame({
'Creation Date': [
pd.Timestamp('2009-09-28 16:11:38.533'),
pd.Timestamp('2009-09-28 17:42:23.207'),
pd.Timestamp('2009-09-28 19:41:13.933'),
pd.Timestamp('2009-09-28 23:40:55.033')],
'UserId': [1,2,4,1]
})
badges = pd.DataFrame({
'UserId': [143, 1, 344],
'Date': [
pd.Timestamp('2009-10-17 17:38:32.590'),
pd.Timestamp('2009-10-19 00:37:23.067'),
pd.Timestamp('2009-10-20 08:37:14.143')
]
})
plt.plot.line(x=(posts['UserId'].CreationDate < badges['UserId'].Date), y=(posts['UserId'].value_counts.mean()))