wikiembed.py / scraps /plot-wikidb.py
brittlewis12's picture
Upload folder using huggingface_hub
7cf8751 verified
raw
history blame
1.33 kB
import sqlite3
import pandas as pd
import matplotlib.pyplot as plt
# Connect to the SQLite database
conn = sqlite3.connect("./wikipedia_simple_20240720.db")
# Query to get the length of each section's text
query = """
SELECT LENGTH(text) as text_length
FROM article_sections;
"""
# Execute the query and load the data into a DataFrame
df = pd.read_sql_query(query, conn)
# Calculate statistics
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}")
# Plot the distribution of section text lengths, focusing on a more relevant range
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()
# Plot a box plot to better visualize the distribution
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()
# Close the connection
conn.close()