|
import sqlite3 |
|
import pandas as pd |
|
import matplotlib.pyplot as plt |
|
|
|
|
|
conn = sqlite3.connect("./wikipedia_simple_20240720.db") |
|
|
|
|
|
query = """ |
|
SELECT LENGTH(text) as text_length |
|
FROM article_sections; |
|
""" |
|
|
|
|
|
df = pd.read_sql_query(query, conn) |
|
|
|
|
|
avg_length = df['text_length'].mean() |
|
min_length = df['text_length'].min() |
|
max_length = df['text_length'].max() |
|
quartiles = df['text_length'].quantile([0.25, 0.5, 0.75]) |
|
|
|
print(f"Average section text length: {avg_length}") |
|
print(f"Minimum section text length: {min_length}") |
|
print(f"Maximum section text length: {max_length}") |
|
print(f"Quartiles:\n{quartiles}") |
|
|
|
|
|
plt.figure(figsize=(10, 6)) |
|
plt.hist(df['text_length'], bins=50, range=(0, 2000), color='skyblue', edgecolor='black') |
|
plt.title('Distribution of Section Text Lengths (0-2000 chars)') |
|
plt.xlabel('Text Length') |
|
plt.ylabel('Frequency') |
|
plt.show() |
|
|
|
|
|
plt.figure(figsize=(10, 6)) |
|
plt.boxplot(df['text_length'], vert=False) |
|
plt.title('Box Plot of Section Text Lengths') |
|
plt.xlabel('Text Length') |
|
plt.show() |
|
|
|
|
|
conn.close() |
|
|