Skip to main content
Syntax highlighting for easier code reading
Source Link
Henry Ecker Mod
  • 35.5k
  • 4
  • 59
  • 89
from stackapi import StackAPI, StackAPIError
import pandas as pd
import plotly.express as px
import urllib

access_token = urllib.parse.parse_qs(urllib.parse.urlparse(auth_url).fragment)[
    "access_token"
][0]


SITE = StackAPI("stackoverflow", key=key, access_token=access_token)
SITE.max_pages = 100

def batch_get(site, so_api, ids, api_kwargs={}):
    n = 100
    return pd.concat(
        [
            pd.json_normalize(
                site.fetch(so_api, ids=ids[i : i + n], **api_kwargs)["items"]
            )
            for i in range(0, len(ids), n)
        ]
    )

# get all my answers
user_ids = [9441404]
dates = (
    pd.date_range("1-jan-2017", "1-jun-2022", freq="MS").astype(int) // 10**9
).tolist()
df_ans = batch_get(
    SITE,
    "users/{ids}/answers",
    user_ids,
    api_kwargs={"fromdata": dates[0], "todate": dates[-1]},
)

# get questions corresponding to answers
df_q = batch_get(SITE, "questions/{ids}", ids=df_ans["question_id"].tolist())

# simple analysis of accepted answers by reputation bucket
df_temp = (
    df_q.groupby([pd.qcut(df_q["owner.reputation"], q=10), "is_answered"])
    .size()
    .reset_index()
    .rename(columns={0: "n"})
    .assign(rep_bin=lambda d: d["owner.reputation"].astype(str))
)

# plot analysis
px.bar(
    df_temp,
    x="rep_bin",
    y="n",
    color="is_answered",
    color_discrete_sequence=["red", "green"],
    barmode="group",
)
from stackapi import StackAPI, StackAPIError
import pandas as pd
import plotly.express as px
import urllib

access_token = urllib.parse.parse_qs(urllib.parse.urlparse(auth_url).fragment)[
    "access_token"
][0]


SITE = StackAPI("stackoverflow", key=key, access_token=access_token)
SITE.max_pages = 100

def batch_get(site, so_api, ids, api_kwargs={}):
    n = 100
    return pd.concat(
        [
            pd.json_normalize(
                site.fetch(so_api, ids=ids[i : i + n], **api_kwargs)["items"]
            )
            for i in range(0, len(ids), n)
        ]
    )

# get all my answers
user_ids = [9441404]
dates = (
    pd.date_range("1-jan-2017", "1-jun-2022", freq="MS").astype(int) // 10**9
).tolist()
df_ans = batch_get(
    SITE,
    "users/{ids}/answers",
    user_ids,
    api_kwargs={"fromdata": dates[0], "todate": dates[-1]},
)

# get questions corresponding to answers
df_q = batch_get(SITE, "questions/{ids}", ids=df_ans["question_id"].tolist())

# simple analysis of accepted answers by reputation bucket
df_temp = (
    df_q.groupby([pd.qcut(df_q["owner.reputation"], q=10), "is_answered"])
    .size()
    .reset_index()
    .rename(columns={0: "n"})
    .assign(rep_bin=lambda d: d["owner.reputation"].astype(str))
)

# plot analysis
px.bar(
    df_temp,
    x="rep_bin",
    y="n",
    color="is_answered",
    color_discrete_sequence=["red", "green"],
    barmode="group",
)
from stackapi import StackAPI, StackAPIError
import pandas as pd
import plotly.express as px
import urllib

access_token = urllib.parse.parse_qs(urllib.parse.urlparse(auth_url).fragment)[
    "access_token"
][0]


SITE = StackAPI("stackoverflow", key=key, access_token=access_token)
SITE.max_pages = 100

def batch_get(site, so_api, ids, api_kwargs={}):
    n = 100
    return pd.concat(
        [
            pd.json_normalize(
                site.fetch(so_api, ids=ids[i : i + n], **api_kwargs)["items"]
            )
            for i in range(0, len(ids), n)
        ]
    )

# get all my answers
user_ids = [9441404]
dates = (
    pd.date_range("1-jan-2017", "1-jun-2022", freq="MS").astype(int) // 10**9
).tolist()
df_ans = batch_get(
    SITE,
    "users/{ids}/answers",
    user_ids,
    api_kwargs={"fromdata": dates[0], "todate": dates[-1]},
)

# get questions corresponding to answers
df_q = batch_get(SITE, "questions/{ids}", ids=df_ans["question_id"].tolist())

# simple analysis of accepted answers by reputation bucket
df_temp = (
    df_q.groupby([pd.qcut(df_q["owner.reputation"], q=10), "is_answered"])
    .size()
    .reset_index()
    .rename(columns={0: "n"})
    .assign(rep_bin=lambda d: d["owner.reputation"].astype(str))
)

# plot analysis
px.bar(
    df_temp,
    x="rep_bin",
    y="n",
    color="is_answered",
    color_discrete_sequence=["red", "green"],
    barmode="group",
)
from stackapi import StackAPI, StackAPIError
import pandas as pd
import plotly.express as px
import urllib

access_token = urllib.parse.parse_qs(urllib.parse.urlparse(auth_url).fragment)[
    "access_token"
][0]


SITE = StackAPI("stackoverflow", key=key, access_token=access_token)
SITE.max_pages = 100

def batch_get(site, so_api, ids, api_kwargs={}):
    n = 100
    return pd.concat(
        [
            pd.json_normalize(
                site.fetch(so_api, ids=ids[i : i + n], **api_kwargs)["items"]
            )
            for i in range(0, len(ids), n)
        ]
    )

# get all my answers
user_ids = [9441404]
dates = (
    pd.date_range("1-jan-2017", "1-jun-2022", freq="MS").astype(int) // 10**9
).tolist()
df_ans = batch_get(
    SITE,
    "users/{ids}/answers",
    user_ids,
    api_kwargs={"fromdata": dates[0], "todate": dates[-1]},
)

# get questions corresponding to answers
df_q = batch_get(SITE, "questions/{ids}", ids=df_ans["question_id"].tolist())

# simple analysis of accepted answers by reputation bucket
df_temp = (
    df_q.groupby([pd.qcut(df_q["owner.reputation"], q=10), "is_answered"])
    .size()
    .reset_index()
    .rename(columns={0: "n"})
    .assign(rep_bin=lambda d: d["owner.reputation"].astype(str))
)

# plot analysis
px.bar(
    df_temp,
    x="rep_bin",
    y="n",
    color="is_answered",
    color_discrete_sequence=["red", "green"],
    barmode="group",
)
added 563 characters in body
Source Link
Rob Raymond
  • 31.1k
  • 6
  • 6
  • x-axis. Discretize reputation of asker into 10 buckets based on quantiles of reputation. hence first bucket are users with <3 rep, second bucket between 3 and 11 rep, ...
  • y-axis. Number of questions in each discrete quantile bucket
  • green bar - where SO has marked question as answered. red-bar were SO has marked question as un-answered

One would expect questions that have valid answers would have a significantly higher proportion of questions marked as answered than not. This is clearly demonstrated as soon as user has > 11 rep in this sample.

  • x-axis. Discretize reputation of asker into 10 buckets based on quantiles of reputation. hence first bucket are users with <3 rep, second bucket between 3 and 11 rep, ...
  • y-axis. Number of questions in each discrete quantile bucket
  • green bar - where SO has marked question as answered. red-bar were SO has marked question as un-answered

One would expect questions that have valid answers would have a significantly higher proportion of questions marked as answered than not. This is clearly demonstrated as soon as user has > 11 rep in this sample.

Source Link
Rob Raymond
  • 31.1k
  • 6
  • 6

It's been stated strongly in a number or answers and comments that new users are fully conversant with all SO policies including question answered

Let's look at this from an analysis of actual data rather than strong opinions which IMHO are not backed up by data analysis and KPIs

Some code to get data, analyse and visualise:

from stackapi import StackAPI, StackAPIError
import pandas as pd
import plotly.express as px
import urllib

access_token = urllib.parse.parse_qs(urllib.parse.urlparse(auth_url).fragment)[
    "access_token"
][0]


SITE = StackAPI("stackoverflow", key=key, access_token=access_token)
SITE.max_pages = 100

def batch_get(site, so_api, ids, api_kwargs={}):
    n = 100
    return pd.concat(
        [
            pd.json_normalize(
                site.fetch(so_api, ids=ids[i : i + n], **api_kwargs)["items"]
            )
            for i in range(0, len(ids), n)
        ]
    )

# get all my answers
user_ids = [9441404]
dates = (
    pd.date_range("1-jan-2017", "1-jun-2022", freq="MS").astype(int) // 10**9
).tolist()
df_ans = batch_get(
    SITE,
    "users/{ids}/answers",
    user_ids,
    api_kwargs={"fromdata": dates[0], "todate": dates[-1]},
)

# get questions corresponding to answers
df_q = batch_get(SITE, "questions/{ids}", ids=df_ans["question_id"].tolist())

# simple analysis of accepted answers by reputation bucket
df_temp = (
    df_q.groupby([pd.qcut(df_q["owner.reputation"], q=10), "is_answered"])
    .size()
    .reset_index()
    .rename(columns={0: "n"})
    .assign(rep_bin=lambda d: d["owner.reputation"].astype(str))
)

# plot analysis
px.bar(
    df_temp,
    x="rep_bin",
    y="n",
    color="is_answered",
    color_discrete_sequence=["red", "green"],
    barmode="group",
)

Resulting graph: enter image description here

Clearly this shows that new / low rep users are not aware of this what to do with an answer.

IMHO wrong conclusion has been reached over balance of guiding new users how to process answers. Concluding any form of guiding new users as bullying is simplistic and wrong.