Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -57,7 +57,6 @@ states = {
|
|
57 |
'Wyoming': {'region': 'West', 'population': 578759, 'area': 253335}
|
58 |
}
|
59 |
|
60 |
-
|
61 |
# Create a function to calculate population density
|
62 |
def calculate_density(population, area):
|
63 |
return population / area
|
@@ -90,19 +89,19 @@ dataframes = []
|
|
90 |
for region, data in regions.items():
|
91 |
population = data['population']
|
92 |
area = data['area']
|
93 |
-
|
94 |
densities = []
|
95 |
-
for state in
|
96 |
-
state_data =
|
97 |
state_population = state_data['population']
|
98 |
state_area = state_data['area']
|
99 |
state_density = calculate_density(state_population, state_area)
|
100 |
densities.append(state_density)
|
101 |
-
df = pd.DataFrame({'State':
|
102 |
dataframes.append(df)
|
103 |
|
104 |
plot_graph(df, region)
|
105 |
|
106 |
# Use Streamlit to display dataframes
|
107 |
for df in dataframes:
|
108 |
-
st.write(df)
|
|
|
57 |
'Wyoming': {'region': 'West', 'population': 578759, 'area': 253335}
|
58 |
}
|
59 |
|
|
|
60 |
# Create a function to calculate population density
|
61 |
def calculate_density(population, area):
|
62 |
return population / area
|
|
|
89 |
for region, data in regions.items():
|
90 |
population = data['population']
|
91 |
area = data['area']
|
92 |
+
states_in_region = data['states']
|
93 |
densities = []
|
94 |
+
for state in states_in_region:
|
95 |
+
state_data = states[state]
|
96 |
state_population = state_data['population']
|
97 |
state_area = state_data['area']
|
98 |
state_density = calculate_density(state_population, state_area)
|
99 |
densities.append(state_density)
|
100 |
+
df = pd.DataFrame({'State': states_in_region, 'Population Density': densities})
|
101 |
dataframes.append(df)
|
102 |
|
103 |
plot_graph(df, region)
|
104 |
|
105 |
# Use Streamlit to display dataframes
|
106 |
for df in dataframes:
|
107 |
+
st.write(df)
|