Created
January 24, 2024 07:45
-
-
Save myselfshravan/759c48d3b16897f2d5f91a27e611c30a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import streamlit as st | |
import pandas as pd | |
import matplotlib.pyplot as plt | |
from urllib.parse import urlparse | |
data = pd.read_csv("csvdata/dark-patterns.csv") | |
st.dataframe(data) | |
# Extracting domain from the 'Website Page' column | |
data['Domain'] = data['Website Page'].apply(lambda x: urlparse(x).netloc) | |
# Counting the frequency of each domain and sorting them from most to least occurrences | |
domain_counts = data['Domain'].value_counts().sort_values(ascending=False) | |
st.divider() | |
st.subheader("Domain Counts") | |
st.write(domain_counts) | |
fig, ax = plt.subplots() | |
# only show top 10 | |
ax.bar(domain_counts.index[:10], domain_counts.values[:10]) | |
plt.title('Distribution of Domains') | |
plt.xticks(rotation=45, ha='right') | |
plt.ylabel('Count') | |
plt.xlabel('Domain') | |
st.pyplot(fig) | |
st.divider() | |
st.subheader("Insights") | |
st.write("The following graphs show the distribution of the data collected.") | |
category_counts = data['Pattern Category'].value_counts() | |
type_counts = data['Pattern Type'].value_counts() | |
deceptive_counts = data['Deceptive?'].value_counts() | |
fig, ax = plt.subplots() | |
ax.bar(category_counts.index, category_counts.values) | |
plt.title('Distribution of Pattern Categories') | |
plt.xticks(rotation=45, ha='right') | |
plt.ylabel('Count') | |
plt.xlabel('Pattern Category') | |
st.pyplot(fig) | |
fig, ax = plt.subplots() | |
ax.bar(type_counts.index, type_counts.values) | |
plt.title('Distribution of Pattern Types') | |
plt.xticks(rotation=45, ha='right') | |
plt.ylabel('Count') | |
plt.xlabel('Pattern Type') | |
st.pyplot(fig) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment