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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import matplotlib.pyplot as plt
|
| 4 |
+
import seaborn as sns
|
| 5 |
+
|
| 6 |
+
# Load the CSV file
|
| 7 |
+
@st.cache_data
|
| 8 |
+
def load_data():
|
| 9 |
+
data = pd.read_csv('SME Survey.csv')
|
| 10 |
+
return data
|
| 11 |
+
|
| 12 |
+
data = load_data()
|
| 13 |
+
|
| 14 |
+
# Title of the app
|
| 15 |
+
st.title('SME Survey Data Exploration')
|
| 16 |
+
|
| 17 |
+
# Display the raw data
|
| 18 |
+
st.subheader('Raw Data')
|
| 19 |
+
st.dataframe(data)
|
| 20 |
+
|
| 21 |
+
# Filters
|
| 22 |
+
st.sidebar.header('Filters')
|
| 23 |
+
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())
|
| 24 |
+
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())
|
| 25 |
+
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())
|
| 26 |
+
|
| 27 |
+
# Apply filters
|
| 28 |
+
filtered_data = data[
|
| 29 |
+
(data['What is the nature of your business?'].isin(business_nature)) &
|
| 30 |
+
(data['How many employees does your business have?'].isin(employee_range)) &
|
| 31 |
+
(data['Are you familiar with the concept of Artificial Intelligence (AI)?'].isin(familiar_with_ai))
|
| 32 |
+
]
|
| 33 |
+
|
| 34 |
+
# Display filtered data
|
| 35 |
+
st.subheader('Filtered Data')
|
| 36 |
+
st.dataframe(filtered_data)
|
| 37 |
+
|
| 38 |
+
# Analysis and Visualizations
|
| 39 |
+
st.subheader('Analysis and Visualizations')
|
| 40 |
+
|
| 41 |
+
# Bar chart for business nature
|
| 42 |
+
st.write('### Distribution of Business Nature')
|
| 43 |
+
fig, ax = plt.subplots(figsize=(10, 6))
|
| 44 |
+
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)
|
| 45 |
+
plt.title('Number of Businesses by Nature')
|
| 46 |
+
plt.xlabel('Count')
|
| 47 |
+
plt.ylabel('Business Nature')
|
| 48 |
+
st.pyplot(fig)
|
| 49 |
+
|
| 50 |
+
# Bar chart for employee range
|
| 51 |
+
st.write('### Distribution of Employee Range')
|
| 52 |
+
fig, ax = plt.subplots(figsize=(10, 6))
|
| 53 |
+
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)
|
| 54 |
+
plt.title('Number of Businesses by Employee Range')
|
| 55 |
+
plt.xlabel('Count')
|
| 56 |
+
plt.ylabel('Employee Range')
|
| 57 |
+
st.pyplot(fig)
|
| 58 |
+
|
| 59 |
+
# Pie chart for familiarity with AI
|
| 60 |
+
st.write('### Familiarity with AI')
|
| 61 |
+
fig, ax = plt.subplots(figsize=(8, 8))
|
| 62 |
+
filtered_data['Are you familiar with the concept of Artificial Intelligence (AI)?'].value_counts().plot(kind='pie', autopct='%1.1f%%', startangle=90)
|
| 63 |
+
plt.title('Familiarity with AI')
|
| 64 |
+
plt.ylabel('')
|
| 65 |
+
st.pyplot(fig)
|
| 66 |
+
|
| 67 |
+
# Bar chart for concerns about AI
|
| 68 |
+
st.write('### Concerns about Adopting AI')
|
| 69 |
+
fig, ax = plt.subplots(figsize=(10, 6))
|
| 70 |
+
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)
|
| 71 |
+
plt.title('Concerns about Adopting AI')
|
| 72 |
+
plt.xlabel('Count')
|
| 73 |
+
plt.ylabel('Concerns')
|
| 74 |
+
st.pyplot(fig)
|
| 75 |
+
|
| 76 |
+
# Bar chart for willingness to invest in AI
|
| 77 |
+
st.write('### Willingness to Invest in AI Solutions Annually')
|
| 78 |
+
fig, ax = plt.subplots(figsize=(10, 6))
|
| 79 |
+
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)
|
| 80 |
+
plt.title('Willingness to Invest in AI Solutions Annually')
|
| 81 |
+
plt.xlabel('Count')
|
| 82 |
+
plt.ylabel('Investment Range')
|
| 83 |
+
st.pyplot(fig)
|
| 84 |
+
|
| 85 |
+
# Bar chart for primary goal in adopting AI
|
| 86 |
+
st.write('### Primary Goal in Adopting AI')
|
| 87 |
+
fig, ax = plt.subplots(figsize=(10, 6))
|
| 88 |
+
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)
|
| 89 |
+
plt.title('Primary Goal in Adopting AI')
|
| 90 |
+
plt.xlabel('Count')
|
| 91 |
+
plt.ylabel('Primary Goal')
|
| 92 |
+
st.pyplot(fig)
|
| 93 |
+
|
| 94 |
+
# Comparison chart for business challenges by business nature
|
| 95 |
+
st.write('### Top Business Challenges by Business Nature')
|
| 96 |
+
challenges = filtered_data['Which business challenges do you face most often? (Rank top 3)'].str.split(';').explode().str.strip()
|
| 97 |
+
challenge_counts = challenges.value_counts()
|
| 98 |
+
challenge_df = filtered_data.merge(challenges.rename('Business Challenge'), left_index=True, right_index=True)
|
| 99 |
+
challenge_pivot = challenge_df.pivot_table(index='Business Challenge', columns='What is the nature of your business?', aggfunc='size', fill_value=0)
|
| 100 |
+
|
| 101 |
+
fig, ax = plt.subplots(figsize=(12, 8))
|
| 102 |
+
challenge_pivot.plot(kind='bar', ax=ax)
|
| 103 |
+
plt.title('Top Business Challenges by Business Nature')
|
| 104 |
+
plt.xlabel('Business Challenge')
|
| 105 |
+
plt.ylabel('Count')
|
| 106 |
+
plt.xticks(rotation=45)
|
| 107 |
+
st.pyplot(fig)
|
| 108 |
+
|
| 109 |
+
# Comparison chart for willingness to invest in AI by business nature
|
| 110 |
+
st.write('### Willingness to Invest in AI by Business Nature')
|
| 111 |
+
investment_df = filtered_data.copy()
|
| 112 |
+
investment_df['Investment Range'] = pd.Categorical(investment_df['How much are you willing to invest in AI solutions annually?'], categories=[
|
| 113 |
+
'Below R 5000 per year',
|
| 114 |
+
'Between R 6000 - R 10 000 per year',
|
| 115 |
+
'Between R 20 000 - R 50 000 per year',
|
| 116 |
+
'More than R50 000 per year'
|
| 117 |
+
], ordered=True)
|
| 118 |
+
|
| 119 |
+
investment_pivot = investment_df.pivot_table(index='Investment Range', columns='What is the nature of your business?', aggfunc='size', fill_value=0)
|
| 120 |
+
|
| 121 |
+
fig, ax = plt.subplots(figsize=(12, 8))
|
| 122 |
+
investment_pivot.plot(kind='bar', ax=ax)
|
| 123 |
+
plt.title('Willingness to Invest in AI by Business Nature')
|
| 124 |
+
plt.xlabel('Investment Range')
|
| 125 |
+
plt.ylabel('Count')
|
| 126 |
+
plt.xticks(rotation=45)
|
| 127 |
+
st.pyplot(fig)
|
| 128 |
+
|
| 129 |
+
# Comparison chart for primary goal in adopting AI by business nature
|
| 130 |
+
st.write('### Primary Goal in Adopting AI by Business Nature')
|
| 131 |
+
goal_df = filtered_data.copy()
|
| 132 |
+
goal_df['Primary Goal'] = goal_df['What would be your primary goal in adopting AI for your business?']
|
| 133 |
+
|
| 134 |
+
goal_pivot = goal_df.pivot_table(index='Primary Goal', columns='What is the nature of your business?', aggfunc='size', fill_value=0)
|
| 135 |
+
|
| 136 |
+
fig, ax = plt.subplots(figsize=(12, 8))
|
| 137 |
+
goal_pivot.plot(kind='bar', ax=ax)
|
| 138 |
+
plt.title('Primary Goal in Adopting AI by Business Nature')
|
| 139 |
+
plt.xlabel('Primary Goal')
|
| 140 |
+
plt.ylabel('Count')
|
| 141 |
+
plt.xticks(rotation=45)
|
| 142 |
+
st.pyplot(fig)
|
| 143 |
+
|
| 144 |
+
# Show the number of businesses using AI tools
|
| 145 |
+
st.write('### Number of Businesses Using AI Tools')
|
| 146 |
+
ai_usage = filtered_data['Have you used any AI tools in your business?'].value_counts()
|
| 147 |
+
st.bar_chart(ai_usage)
|
| 148 |
+
|
| 149 |
+
# Show the number of businesses interested in a free trial of AI tools
|
| 150 |
+
st.write('### Number of Businesses Interested in a Free Trial of AI Tools')
|
| 151 |
+
free_trial_interest = filtered_data['Would you be interested in a free trial of AI tools tailored to your business?'].value_counts()
|
| 152 |
+
st.bar_chart(free_trial_interest)
|
| 153 |
+
|
| 154 |
+
# Show the number of businesses knowing their sales revenue in real time
|
| 155 |
+
st.write('### Number of Businesses Knowing Sales Revenue in Real Time')
|
| 156 |
+
real_time_revenue = filtered_data['Do you know your sales revenue in real time?'].value_counts()
|
| 157 |
+
st.bar_chart(real_time_revenue)
|
| 158 |
+
|
| 159 |
+
# Show the preferred method of learning about new technologies
|
| 160 |
+
st.write('### Preferred Method of Learning about New Technologies')
|
| 161 |
+
learning_method = filtered_data['How do you prefer to learn about new technologies like AI?'].value_counts()
|
| 162 |
+
st.bar_chart(learning_method)
|
| 163 |
+
|
| 164 |
+
# Show the number of businesses by primary goal in adopting AI
|
| 165 |
+
st.write('### Number of Businesses by Primary Goal in Adopting AI')
|
| 166 |
+
primary_goal = filtered_data['What would be your primary goal in adopting AI for your business?'].value_counts()
|
| 167 |
+
st.bar_chart(primary_goal)
|
| 168 |
+
|
| 169 |
+
# Show the number of businesses by familiarity with AI
|
| 170 |
+
st.write('### Number of Businesses by Familiarity with AI')
|
| 171 |
+
familiarity_with_ai = filtered_data['Are you familiar with the concept of Artificial Intelligence (AI)?'].value_counts()
|
| 172 |
+
st.bar_chart(familiarity_with_ai)
|
| 173 |
+
|
| 174 |
+
# Show the number of businesses by concerns about AI
|
| 175 |
+
st.write('### Number of Businesses by Concerns about AI')
|
| 176 |
+
concerns_about_ai = filtered_data['What concerns do you have about adopting AI in your business?'].value_counts()
|
| 177 |
+
st.bar_chart(concerns_about_ai)
|
| 178 |
+
|
| 179 |
+
# Show the number of businesses by willingness to invest in AI
|
| 180 |
+
st.write('### Number of Businesses by Willingness to Invest in AI')
|
| 181 |
+
willingness_to_invest = filtered_data['How much are you willing to invest in AI solutions annually?'].value_counts()
|
| 182 |
+
st.bar_chart(willingness_to_invest)
|
| 183 |
+
|
| 184 |
+
# Show the number of businesses by current technological solutions
|
| 185 |
+
st.write('### Number of Businesses by Current Technological Solutions')
|
| 186 |
+
current_tech_solutions = filtered_data['What technological solutions do you currently use?'].str.split(';').explode().str.strip().value_counts()
|
| 187 |
+
st.bar_chart(current_tech_solutions)
|
| 188 |
+
|
| 189 |
+
# Show the number of businesses by needed technology solutions
|
| 190 |
+
st.write('### Number of Businesses by Needed Technology Solutions')
|
| 191 |
+
needed_tech_solutions = filtered_data['What technology solutions do you need for your business?'].str.split(';').explode().str.strip().value_counts()
|
| 192 |
+
st.bar_chart(needed_tech_solutions)
|
| 193 |
+
|
| 194 |
+
# Show the number of businesses by operational tasks handling
|
| 195 |
+
st.write('### Number of Businesses by Operational Tasks Handling')
|
| 196 |
+
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()
|
| 197 |
+
st.bar_chart(operational_tasks)
|
| 198 |
+
|
| 199 |
+
# Show the number of businesses by business challenges
|
| 200 |
+
st.write('### Number of Businesses by Business Challenges')
|
| 201 |
+
business_challenges = filtered_data['Which business challenges do you face most often? (Rank top 3)'].str.split(';').explode().str.strip().value_counts()
|
| 202 |
+
st.bar_chart(business_challenges)
|
| 203 |
+
|
| 204 |
+
# Run the app
|
| 205 |
+
if __name__ == '__main__':
|
| 206 |
+
st.run()
|