<jupyter_start><jupyter_text>bicycles- [Tags] 525- [PostLinks] 6,140- [Badges] 80,935- [Users] 40,571- [Votes] 283,664- [Comments] 131,281- [Posts] 56,860- [PostHistory] 146,878 coffee- [Tags] 115- [PostLinks] 602- [Comments] 4,365- [Badges] 10,852- [Votes] 20,663- [Posts] 3,936- [Users] 8,256- [PostHistory] 10,178 ukrainian- [Tags] 120- [PostLinks] 399- [Badges] 6,248- [Users] 3,080- [Comments] 6,954- [Votes] 28,867- [Posts] 5,069- [PostHistory] 16,102<jupyter_code>import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from IPython.display import display
%run common.ipynb<jupyter_output><empty_output><jupyter_text>Załadowanie danych<jupyter_code>bicycles_posts_df = read_stackexchange(ModelType.POSTS, ForumType.BICYCLES)
coffee_posts_df = read_stackexchange(ModelType.POSTS, ForumType.COFFEE)
ukrainian_posts_df = read_stackexchange(ModelType.POSTS, ForumType.UKRAINIAN)
def analyze_v1(posts):
    # PostTypeId: 1 -> Question, 2 -> Answer
    questions = posts.loc[posts.PostTypeId == 1, ['Id', 'CreationDate', 'Title', 'OwnerUserId']]
    answers = posts.loc[posts.PostTypeId == 2, ['Id', 'ParentId', 'CreationDate', 'Body', 'OwnerUserId']]
    
    questions['CreationDate_datetime'] = pd.to_datetime(questions['CreationDate'])
    answers['CreationDate_datetime'] = pd.to_datetime(answers['CreationDate'])
    
    df = questions.join(answers.set_index('ParentId'), on = 'Id', 
                        lsuffix='_question', rsuffix='_answer', how = 'inner')
    df['diff_time'] = df['CreationDate_datetime_answer'] - df['CreationDate_datetime_question']
    #df['diff_hours']=df['diff_hours']/np.timedelta64(1,'h')
    
    
    # Aggregate diff_time by Id_question
    df = df.groupby('Id_question').agg({'diff_time': ['min', 'max']})
    df.columns = ['_'.join(col) for col in df.columns.values]
    
    # Get (min, max) from min and max
    return df.agg({'diff_time_min': ['min', 'max'], 'diff_time_max': ['min', 'max']})

analyze_v1(bicycles_posts_df)
analyze_v1(coffee_posts_df)
analyze_v1(ukrainian_posts_df)<jupyter_output><empty_output><jupyter_text>Otrzymujemy ciekawe wyniki - zerowe i ujemne. Zacznijmy od ujemnych.Po krótkim dochodzeniu, znajdujemy winowajcę:<jupyter_code>def nostradamus():
    questions = bicycles_posts_df.loc[bicycles_posts_df.PostTypeId == 1, ['Id', 'CreationDate', 'Title']]
    answers = bicycles_posts_df.loc[bicycles_posts_df.PostTypeId == 2, ['Id', 'ParentId', 'CreationDate']]
    
    questions['CreationDate_datetime'] = pd.to_datetime(questions['CreationDate'])
    answers['CreationDate_datetime'] = pd.to_datetime(answers['CreationDate'])
    
    df = questions.join(answers.set_index('ParentId'), on = 'Id', 
                        lsuffix='_question', rsuffix='_answer', how = 'inner')
    df['diff_time'] = df['CreationDate_datetime_answer'] - df['CreationDate_datetime_question']
    #df['diff_hours']=df['diff_hours']/np.timedelta64(1,'h')
    
    
    return df.loc[df['Id_question'] == 10069, ['Title', 'CreationDate_question', 'CreationDate_answer', 'diff_time']]
nostradamus()<jupyter_output><empty_output><jupyter_text>Rzeczywiście użytkownik [coco](https://bicycles.stackexchange.com/users/4394/coco), znany dalej jako Nostradamus zadał (jedyne w swojej karierze na *bicycles.stackexchange.com*) pytanie w 2012 roku, a następnie (chociaż chciałoby się powiedzieć *poprzednio*) użytownicy [<NAME>](https://bicycles.stackexchange.com/users/1584/daniel-r-hicks) oraz [Angelo](https://bicycles.stackexchange.com/users/1998/angelo) odpowiedzieli w 2011 roku.> asked Jun 26 '12 at 15:56>> coco> answered Sep 9 '11 at 12:13>> <NAME>> answered Sep 9 '11 at 13:09>> AngeloDowód podróży w czasie można znaleźć dalej wiszący na forum: https://bicycles.stackexchange.com/questions/10069/does-drafting-cause-resistance-to-the-lead-rider  Teraz przejdźmy do wyników zerowych.Poniższa analiza pokazuje, że wszystkie odpowiedzi, które zostały najwidoczniej napisane poniżej 1 tysięcznej sekundy po zamieszczeniu pytania należą do tego samego autora, który zadał pytanie. Znalezienie powodu dla tego fenomenu jest trywialne i pozostawiamy je czytelnikom jako ćwiczenie.<jupyter_code>def zeroday(posts):
    # PostTypeId: 1 -> Question, 2 -> Answer
    questions = posts.loc[posts.PostTypeId == 1, ['Id', 'CreationDate', 'Title', 'OwnerUserId']]
    answers = posts.loc[posts.PostTypeId == 2, ['Id', 'ParentId', 'CreationDate', 'Body', 'OwnerUserId']]
    
    questions['CreationDate_datetime'] = pd.to_datetime(questions['CreationDate'])
    answers['CreationDate_datetime'] = pd.to_datetime(answers['CreationDate'])
    
    df = questions.join(answers.set_index('ParentId'), on = 'Id', 
                        lsuffix='_question', rsuffix='_answer', how = 'inner')
    df['diff_time'] = df['CreationDate_datetime_answer'] - df['CreationDate_datetime_question']
    
    df['IsSame'] = df['OwnerUserId_question'] == df['OwnerUserId_answer']
    
    df = df.loc[
        df['CreationDate_datetime_question'] == df['CreationDate_datetime_answer'],
        ['Id_question', 'Title', 'IsSame']
    ]
    return df

zeroday(bicycles_posts_df)
zeroday(coffee_posts_df)
zeroday(ukrainian_posts_df)<jupyter_output><empty_output><jupyter_text>Wersja 2W tej wersji pomijamy wyniki niedodatnie<jupyter_code>def analyze_v2(posts):
    # PostTypeId: 1 -> Question, 2 -> Answer
    questions = posts.loc[posts.PostTypeId == 1, ['Id', 'CreationDate', 'Title', 'OwnerUserId']]
    answers = posts.loc[posts.PostTypeId == 2, ['Id', 'ParentId', 'CreationDate', 'Body', 'OwnerUserId']]
    
    questions['CreationDate_datetime'] = pd.to_datetime(questions['CreationDate'])
    answers['CreationDate_datetime'] = pd.to_datetime(answers['CreationDate'])
    
    df = questions.join(answers.set_index('ParentId'), on = 'Id', 
                        lsuffix='_question', rsuffix='_answer', how = 'inner')
    df['diff_time'] = df['CreationDate_datetime_answer'] - df['CreationDate_datetime_question']
    #df['diff_hours']=df['diff_hours']/np.timedelta64(1,'h')
    
    df = df.loc[df['CreationDate_datetime_answer'] > df['CreationDate_datetime_question']]
    
    # Aggregate diff_time by Id_question
    df = df.groupby('Id_question').agg({'diff_time': ['min', 'max']})
    df.columns = ['_'.join(col) for col in df.columns.values]
    
    # Get (min, max) from min and max
    return df.agg({'diff_time_min': ['min', 'max'], 'diff_time_max': ['min', 'max']})

for forum_type in ForumType:
    posts_df = read_stackexchange(ModelType.POSTS, forum_type)
    print(forum_type.value)
    display(analyze_v2(posts_df))<jupyter_output>bicycles