Skip to content

Commit 93b2784

Browse files
authored
Merge pull request recodehive#269 from revanth1718/main
BUG FIXED
2 parents e9e554e + 40a327d commit 93b2784

File tree

4 files changed

+16
-11
lines changed

4 files changed

+16
-11
lines changed
20.2 KB
Binary file not shown.
Binary file not shown.

streamlit/functions.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,8 @@ def ai_graphs():
263263
st.title('AI Survey Responses')
264264
df = full_data2018[['AIDangerous', 'AIInteresting', 'AIResponsible', 'AIFuture']]
265265

266-
df = df.applymap(lambda x: x.strip() if isinstance(x, str) else x)
266+
# Correct replacement of applymap
267+
df = df.apply(lambda col: col.map(lambda x: x.strip() if isinstance(x, str) else x) if col.dtype == 'object' else col)
267268

268269
short_mapping = {
269270
'Algorithms making important decisions': 'Algorithms',
@@ -286,8 +287,7 @@ def ai_graphs():
286287
plot_value_counts_plotly('AIDangerous', df, col1)
287288
plot_value_counts_plotly('AIInteresting', df, col1)
288289
plot_value_counts_plotly('AIResponsible', df, col2)
289-
plot_value_counts_plotly('AIFuture', df, col2)
290-
290+
plot_value_counts_plotly('AIFuture', df, col2)
291291

292292
def result_plot(data):
293293
new_index = data.Rates.sort_values(ascending=False).index

streamlit/home.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,32 @@
1010
import random
1111
import functions as ff
1212
import main_analysis as main
13+
import os
1314

1415
#######################################
1516
# DATA LOADING
1617
#######################################
1718

1819
st.set_page_config(layout='wide')
1920

21+
# Determine the base path
22+
base_path = os.path.dirname(__file__)
23+
2024
# Loading data files
21-
df = pd.read_csv('df2020.csv')
22-
df2018 = pd.read_csv('df2018.csv')
23-
full_data2018 = pd.read_csv('survey_results_sample_2018.csv')
24-
full_data2019 = pd.read_csv('survey_results_sample_2019.csv')
25-
full_df2020 = pd.read_csv('survey_results_sample_2020.csv')
26-
df2019 = pd.read_csv('df2019.csv')
25+
df = pd.read_csv(os.path.join(base_path, 'df2020.csv'))
26+
df2018 = pd.read_csv(os.path.join(base_path, 'df2018.csv'))
27+
full_data2018 = pd.read_csv(os.path.join(base_path, 'survey_results_sample_2018.csv'))
28+
full_data2019 = pd.read_csv(os.path.join(base_path, 'survey_results_sample_2019.csv'))
29+
full_df2020 = pd.read_csv(os.path.join(base_path, 'survey_results_sample_2020.csv'))
30+
df2019 = pd.read_csv(os.path.join(base_path, 'df2019.csv'))
2731

2832
# Filter the 2020 dataframe
2933
df2020 = df[df['SalaryUSD'] < 200000]
3034

3135
# Load CSS file
3236
def local_css(file_name):
33-
with open(file_name) as f:
37+
css_path = os.path.join(base_path, file_name)
38+
with open(css_path) as f:
3439
st.markdown(f'<style>{f.read()}</style>', unsafe_allow_html=True)
3540

3641
local_css("style.css")
@@ -61,7 +66,7 @@ def local_css(file_name):
6166
full_data2018.rename(columns={'ConvertedSalary': 'SalaryUSD'}, inplace=True)
6267

6368
# Strip leading and trailing whitespace from all columns in df_ai
64-
df_ai = df_ai.applymap(lambda x: x.strip() if isinstance(x, str) else x)
69+
df_ai = df_ai.apply(lambda x: x.str.strip() if x.dtype == "object" else x)
6570

6671
# Mapping for shorter versions
6772
short_mapping = {

0 commit comments

Comments
 (0)