import streamlit as st import pandas as pd import matplotlib.pyplot as plt import seaborn as sns # Load the CSV file @st.cache_data def load_data(): data = pd.read_csv('SME Survey.csv') return data data = load_data() # Title of the app st.title('SME Survey Data Exploration') # Display the raw data st.subheader('Raw Data') st.dataframe(data) # Filters st.sidebar.header('Filters') business_nature = st.sidebar.multiselect('Select Business Nature', data['What is the nature of your business?'].unique(), default=data['What is the nature of your business?'].unique()) employee_range = st.sidebar.multiselect('Select Employee Range', data['How many employees does your business have?'].unique(), default=data['How many employees does your business have?'].unique()) familiar_with_ai = st.sidebar.multiselect('Familiarity with AI', data['Are you familiar with the concept of Artificial Intelligence (AI)?'].unique(), default=data['Are you familiar with the concept of Artificial Intelligence (AI)?'].unique()) # Apply filters filtered_data = data[ (data['What is the nature of your business?'].isin(business_nature)) & (data['How many employees does your business have?'].isin(employee_range)) & (data['Are you familiar with the concept of Artificial Intelligence (AI)?'].isin(familiar_with_ai)) ] # Display filtered data st.subheader('Filtered Data') st.dataframe(filtered_data) # Analysis and Visualizations st.subheader('Analysis and Visualizations') # Bar chart for business nature st.write('### Distribution of Business Nature') fig, ax = plt.subplots(figsize=(10, 6)) sns.countplot(y=filtered_data['What is the nature of your business?'], order=filtered_data['What is the nature of your business?'].value_counts().index) plt.title('Number of Businesses by Nature') plt.xlabel('Count') plt.ylabel('Business Nature') st.pyplot(fig) # Bar chart for employee range st.write('### Distribution of Employee Range') fig, ax = plt.subplots(figsize=(10, 6)) sns.countplot(y=filtered_data['How many employees does your business have?'], order=filtered_data['How many employees does your business have?'].value_counts().index) plt.title('Number of Businesses by Employee Range') plt.xlabel('Count') plt.ylabel('Employee Range') st.pyplot(fig) # Pie chart for familiarity with AI st.write('### Familiarity with AI') fig, ax = plt.subplots(figsize=(8, 8)) filtered_data['Are you familiar with the concept of Artificial Intelligence (AI)?'].value_counts().plot(kind='pie', autopct='%1.1f%%', startangle=90) plt.title('Familiarity with AI') plt.ylabel('') st.pyplot(fig) # Bar chart for concerns about AI st.write('### Concerns about Adopting AI') fig, ax = plt.subplots(figsize=(10, 6)) sns.countplot(y=filtered_data['What concerns do you have about adopting AI in your business?'], order=filtered_data['What concerns do you have about adopting AI in your business?'].value_counts().index) plt.title('Concerns about Adopting AI') plt.xlabel('Count') plt.ylabel('Concerns') st.pyplot(fig) # Bar chart for willingness to invest in AI st.write('### Willingness to Invest in AI Solutions Annually') fig, ax = plt.subplots(figsize=(10, 6)) sns.countplot(y=filtered_data['How much are you willing to invest in AI solutions annually?'], order=filtered_data['How much are you willing to invest in AI solutions annually?'].value_counts().index) plt.title('Willingness to Invest in AI Solutions Annually') plt.xlabel('Count') plt.ylabel('Investment Range') st.pyplot(fig) # Bar chart for primary goal in adopting AI st.write('### Primary Goal in Adopting AI') fig, ax = plt.subplots(figsize=(10, 6)) sns.countplot(y=filtered_data['What would be your primary goal in adopting AI for your business?'], order=filtered_data['What would be your primary goal in adopting AI for your business?'].value_counts().index) plt.title('Primary Goal in Adopting AI') plt.xlabel('Count') plt.ylabel('Primary Goal') st.pyplot(fig) # Comparison chart for business challenges by business nature st.write('### Top Business Challenges by Business Nature') challenges = filtered_data['Which business challenges do you face most often? (Rank top 3)'].str.split(';').explode().str.strip() challenge_counts = challenges.value_counts() challenge_df = filtered_data.merge(challenges.rename('Business Challenge'), left_index=True, right_index=True) challenge_pivot = challenge_df.pivot_table(index='Business Challenge', columns='What is the nature of your business?', aggfunc='size', fill_value=0) fig, ax = plt.subplots(figsize=(12, 8)) challenge_pivot.plot(kind='bar', ax=ax) plt.title('Top Business Challenges by Business Nature') plt.xlabel('Business Challenge') plt.ylabel('Count') plt.xticks(rotation=45) st.pyplot(fig) # Comparison chart for willingness to invest in AI by business nature st.write('### Willingness to Invest in AI by Business Nature') investment_df = filtered_data.copy() investment_df['Investment Range'] = pd.Categorical(investment_df['How much are you willing to invest in AI solutions annually?'], categories=[ 'Below R 5000 per year', 'Between R 6000 - R 10 000 per year', 'Between R 20 000 - R 50 000 per year', 'More than R50 000 per year' ], ordered=True) investment_pivot = investment_df.pivot_table(index='Investment Range', columns='What is the nature of your business?', aggfunc='size', fill_value=0) fig, ax = plt.subplots(figsize=(12, 8)) investment_pivot.plot(kind='bar', ax=ax) plt.title('Willingness to Invest in AI by Business Nature') plt.xlabel('Investment Range') plt.ylabel('Count') plt.xticks(rotation=45) st.pyplot(fig) # Comparison chart for primary goal in adopting AI by business nature st.write('### Primary Goal in Adopting AI by Business Nature') goal_df = filtered_data.copy() goal_df['Primary Goal'] = goal_df['What would be your primary goal in adopting AI for your business?'] goal_pivot = goal_df.pivot_table(index='Primary Goal', columns='What is the nature of your business?', aggfunc='size', fill_value=0) fig, ax = plt.subplots(figsize=(12, 8)) goal_pivot.plot(kind='bar', ax=ax) plt.title('Primary Goal in Adopting AI by Business Nature') plt.xlabel('Primary Goal') plt.ylabel('Count') plt.xticks(rotation=45) st.pyplot(fig) # Show the number of businesses using AI tools st.write('### Number of Businesses Using AI Tools') ai_usage = filtered_data['Have you used any AI tools in your business?'].value_counts() st.bar_chart(ai_usage) # Show the number of businesses interested in a free trial of AI tools st.write('### Number of Businesses Interested in a Free Trial of AI Tools') free_trial_interest = filtered_data['Would you be interested in a free trial of AI tools tailored to your business?'].value_counts() st.bar_chart(free_trial_interest) # Show the number of businesses knowing their sales revenue in real time st.write('### Number of Businesses Knowing Sales Revenue in Real Time') real_time_revenue = filtered_data['Do you know your sales revenue in real time?'].value_counts() st.bar_chart(real_time_revenue) # Show the preferred method of learning about new technologies st.write('### Preferred Method of Learning about New Technologies') learning_method = filtered_data['How do you prefer to learn about new technologies like AI?'].value_counts() st.bar_chart(learning_method) # Show the number of businesses by primary goal in adopting AI st.write('### Number of Businesses by Primary Goal in Adopting AI') primary_goal = filtered_data['What would be your primary goal in adopting AI for your business?'].value_counts() st.bar_chart(primary_goal) # Show the number of businesses by familiarity with AI st.write('### Number of Businesses by Familiarity with AI') familiarity_with_ai = filtered_data['Are you familiar with the concept of Artificial Intelligence (AI)?'].value_counts() st.bar_chart(familiarity_with_ai) # Show the number of businesses by concerns about AI st.write('### Number of Businesses by Concerns about AI') concerns_about_ai = filtered_data['What concerns do you have about adopting AI in your business?'].value_counts() st.bar_chart(concerns_about_ai) # Show the number of businesses by willingness to invest in AI st.write('### Number of Businesses by Willingness to Invest in AI') willingness_to_invest = filtered_data['How much are you willing to invest in AI solutions annually?'].value_counts() st.bar_chart(willingness_to_invest) # Show the number of businesses by current technological solutions st.write('### Number of Businesses by Current Technological Solutions') current_tech_solutions = filtered_data['What technological solutions do you currently use?'].str.split(';').explode().str.strip().value_counts() st.bar_chart(current_tech_solutions) # Show the number of businesses by needed technology solutions st.write('### Number of Businesses by Needed Technology Solutions') needed_tech_solutions = filtered_data['What technology solutions do you need for your business?'].str.split(';').explode().str.strip().value_counts() st.bar_chart(needed_tech_solutions) # Show the number of businesses by operational tasks handling st.write('### Number of Businesses by Operational Tasks Handling') operational_tasks = filtered_data['How do you currently handle the operational tasks of Customer support; Inventory management; Accounting/Finance and etc?'].str.split(';').explode().str.strip().value_counts() st.bar_chart(operational_tasks) # Show the number of businesses by business challenges st.write('### Number of Businesses by Business Challenges') business_challenges = filtered_data['Which business challenges do you face most often? (Rank top 3)'].str.split(';').explode().str.strip().value_counts() st.bar_chart(business_challenges)