Spaces:
Runtime error
Runtime error
Create TenTenDistrib.py
Browse files- TenTenDistrib.py +54 -0
TenTenDistrib.py
ADDED
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import pandas as pd
|
2 |
+
import streamlit as st
|
3 |
+
|
4 |
+
# Load the XLSX file using pandas
|
5 |
+
data = pd.read_excel('your_file.xlsx')
|
6 |
+
|
7 |
+
# Perform EDA on the data
|
8 |
+
# ...
|
9 |
+
|
10 |
+
# Function to create the top ten ordered distribution
|
11 |
+
def create_top_ten_distribution(data, column):
|
12 |
+
# Count the unique values and blanks in the specified column
|
13 |
+
value_counts = data[column].value_counts(dropna=False)
|
14 |
+
|
15 |
+
# Create a DataFrame with the top ten values and their counts
|
16 |
+
top_ten_df = pd.DataFrame({'Value': value_counts.index, 'Count': value_counts.values})
|
17 |
+
top_ten_df['Rank'] = range(1, len(top_ten_df) + 1)
|
18 |
+
|
19 |
+
return top_ten_df.head(10)
|
20 |
+
|
21 |
+
# Function to display the filtered dataframe based on rank
|
22 |
+
def display_filtered_dataframe(data, column, rank):
|
23 |
+
# Get the value corresponding to the specified rank
|
24 |
+
value = top_ten_df[top_ten_df['Rank'] == rank]['Value'].values[0]
|
25 |
+
|
26 |
+
# Filter the dataframe based on the value
|
27 |
+
filtered_df = data[data[column] == value]
|
28 |
+
|
29 |
+
return filtered_df
|
30 |
+
|
31 |
+
# Streamlit app
|
32 |
+
def main():
|
33 |
+
st.title('Top Ten Distribution and Filtered Dataframe')
|
34 |
+
|
35 |
+
# Specify the column for creating the top ten distribution
|
36 |
+
column = 'your_column_name'
|
37 |
+
|
38 |
+
# Create the top ten ordered distribution
|
39 |
+
top_ten_df = create_top_ten_distribution(data, column)
|
40 |
+
|
41 |
+
# Display the top ten distribution as a markdown table
|
42 |
+
st.markdown('### Top Ten Distribution')
|
43 |
+
st.markdown(top_ten_df.to_markdown(index=False))
|
44 |
+
|
45 |
+
# Get the user input for the rank
|
46 |
+
rank = st.number_input('Enter the rank to filter the dataframe', min_value=1, max_value=10, value=1, step=1)
|
47 |
+
|
48 |
+
# Display the filtered dataframe based on the rank
|
49 |
+
filtered_df = display_filtered_dataframe(data, column, rank)
|
50 |
+
st.markdown(f'### Filtered Dataframe (Rank: {rank})')
|
51 |
+
st.dataframe(filtered_df)
|
52 |
+
|
53 |
+
if __name__ == '__main__':
|
54 |
+
main()
|