Datasets:
File size: 1,334 Bytes
7cf8751 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
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()
|