Skip to content

Commit a9d860e

Browse files
committed
Add data analysis file for scatter plot visualization
1 parent 83cd170 commit a9d860e

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

data_analysis (1).py

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# -*- coding: utf-8 -*-
2+
"""Data analysis.ipynb
3+
4+
Automatically generated by Colab.
5+
6+
Original file is located at
7+
https://colab.research.google.com/drive/1rgZ1KKaswBXKXYF_m5svCLsk6eBzLBT9
8+
"""
9+
10+
!pip install streamlit
11+
12+
import pandas as pd
13+
import streamlit as st
14+
import seaborn as sns
15+
import matplotlib.pyplot as plt
16+
17+
def load_and_scatterplot(year):
18+
19+
file_path = f"Survey_results_sample_{year}.csv"
20+
21+
try:
22+
data = pd.read_csv(file_path)
23+
except FileNotFoundError:
24+
st.error(f"File for the year {year} not found!")
25+
return None
26+
27+
28+
29+
cols = ['Country', 'YearsCodePro', 'ConvertedCompYearly', 'DevType']
30+
filtered_data = data[cols].dropna()
31+
32+
filtered_data['YearsCodePro'] = pd.to_numeric(filtered_data['YearsCodePro'], errors='coerce')
33+
filtered_data = filtered_data.dropna(subset=['YearsCodePro'])
34+
# Create a scatter plot for YearsCodePro vs ConvertedCompYearly, color-coded by DevType
35+
st.write(f"Scatter Plot: Years of Professional Coding Experience vs Yearly Compensation for {year}")
36+
37+
plt.figure(figsize=(14, 8))
38+
39+
scatter = sns.scatterplot(
40+
data=filtered_data,
41+
x='YearsCodePro',
42+
y='ConvertedCompYearly',
43+
hue='DevType',
44+
style='Country',
45+
palette='deep',
46+
s=100,
47+
alpha=0.6
48+
)
49+
50+
scatter.legend(loc='center left', bbox_to_anchor=(1, 0.5), title='Developer Type')
51+
52+
plt.title(f'YearsCodePro vs ConvertedCompYearly ({year}), colored by DevType', fontsize=16)
53+
plt.xlabel('Years of Professional Coding Experience', fontsize=14)
54+
plt.ylabel('Yearly Compensation (USD)', fontsize=14)
55+
56+
st.pyplot(plt)
57+

0 commit comments

Comments
 (0)