ThejasRao commited on
Commit
87a2608
ยท
1 Parent(s): f3e88b4

Fix: Readme

Browse files
Files changed (1) hide show
  1. streamlit_app.py +62 -8
streamlit_app.py CHANGED
@@ -180,29 +180,83 @@ if st.session_state.authenticated:
180
  with st.expander("View grouped data (first 10 rows)"):
181
  st.dataframe(df_grouped.head(10))
182
 
183
- st.write(f"๐Ÿ“Š **Plotting {len(df_grouped)} actual data points (no gap filling)**")
 
 
 
 
 
 
 
 
 
 
 
 
184
 
185
  st.subheader(f"๐Ÿ“ˆ Trends for {selected_state} ({'Market: ' + selected_market if market_wise else 'State'})")
186
 
187
  if data_type == "Both":
 
188
  scaler = MinMaxScaler()
189
- df_grouped[['Scaled Price', 'Scaled Arrivals']] = scaler.fit_transform(df_grouped[['Modal Price (Rs./Quintal)', 'Arrivals (Tonnes)']])
 
 
 
190
  import plotly.graph_objects as go
191
  fig = go.Figure()
192
- fig.add_trace(go.Scatter(x=df_grouped['Reported Date'], y=df_grouped['Scaled Price'], mode='lines', name='Scaled Price', line=dict(width=1, color='green')))
193
- fig.add_trace(go.Scatter(x=df_grouped['Reported Date'], y=df_grouped['Scaled Arrivals'], mode='lines', name='Scaled Arrivals', line=dict(width=1, color='blue')))
194
- fig.update_layout(title="Price and Arrivals Trend", xaxis_title='Date', yaxis_title='Scaled Values', template='plotly_white')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
195
  st.plotly_chart(fig, use_container_width=True)
196
  elif data_type == "Price":
 
197
  import plotly.graph_objects as go
198
  fig = go.Figure()
199
- fig.add_trace(go.Scatter(x=df_grouped['Reported Date'], y=df_grouped['Modal Price (Rs./Quintal)'], mode='lines', name='Modal Price', line=dict(width=1, color='green')))
 
 
 
 
 
 
200
  fig.update_layout(title="Modal Price Trend", xaxis_title='Date', yaxis_title='Price (/Quintall)', template='plotly_white')
201
  st.plotly_chart(fig, use_container_width=True)
202
- else:
 
203
  import plotly.graph_objects as go
204
  fig = go.Figure()
205
- fig.add_trace(go.Scatter(x=df_grouped['Reported Date'], y=df_grouped['Arrivals (Tonnes)'], mode='lines', name='Arrivals', line=dict(width=1, color='blue')))
 
 
 
 
 
 
206
  fig.update_layout(title="Arrivals Trend", xaxis_title='Date', yaxis_title='Volume (in Tonnes)', template='plotly_white')
207
  st.plotly_chart(fig, use_container_width=True)
208
  else:
 
180
  with st.expander("View grouped data (first 10 rows)"):
181
  st.dataframe(df_grouped.head(10))
182
 
183
+ # Create complete date range and fill gaps
184
+ date_range = pd.date_range(
185
+ start=df_grouped['Reported Date'].min(),
186
+ end=df_grouped['Reported Date'].max(),
187
+ freq='D'
188
+ )
189
+ df_grouped = df_grouped.set_index('Reported Date').reindex(date_range).rename_axis('Reported Date').reset_index()
190
+
191
+ # Fill missing values using the working method
192
+ df_grouped['Arrivals (Tonnes)'] = df_grouped['Arrivals (Tonnes)'].fillna(method='ffill').fillna(method='bfill')
193
+ df_grouped['Modal Price (Rs./Quintal)'] = df_grouped['Modal Price (Rs./Quintal)'].fillna(method='ffill').fillna(method='bfill')
194
+
195
+ st.write(f"๐Ÿ“Š **Plotting {len(df_grouped)} data points after filling date gaps**")
196
 
197
  st.subheader(f"๐Ÿ“ˆ Trends for {selected_state} ({'Market: ' + selected_market if market_wise else 'State'})")
198
 
199
  if data_type == "Both":
200
+ # Min-Max Scaling
201
  scaler = MinMaxScaler()
202
+ df_grouped[['Scaled Price', 'Scaled Arrivals']] = scaler.fit_transform(
203
+ df_grouped[['Modal Price (Rs./Quintal)', 'Arrivals (Tonnes)']]
204
+ )
205
+
206
  import plotly.graph_objects as go
207
  fig = go.Figure()
208
+
209
+ fig.add_trace(go.Scatter(
210
+ x=df_grouped['Reported Date'],
211
+ y=df_grouped['Scaled Price'],
212
+ mode='lines',
213
+ name='Scaled Price',
214
+ line=dict(width=1, color='green'),
215
+ text=df_grouped['Modal Price (Rs./Quintal)'],
216
+ hovertemplate='Date: %{x}<br>Scaled Price: %{y:.2f}<br>Actual Price: %{text:.2f}<extra></extra>'
217
+ ))
218
+
219
+ fig.add_trace(go.Scatter(
220
+ x=df_grouped['Reported Date'],
221
+ y=df_grouped['Scaled Arrivals'],
222
+ mode='lines',
223
+ name='Scaled Arrivals',
224
+ line=dict(width=1, color='blue'),
225
+ text=df_grouped['Arrivals (Tonnes)'],
226
+ hovertemplate='Date: %{x}<br>Scaled Arrivals: %{y:.2f}<br>Actual Arrivals: %{text:.2f}<extra></extra>'
227
+ ))
228
+
229
+ fig.update_layout(
230
+ title="Price and Arrivals Trend",
231
+ xaxis_title='Date',
232
+ yaxis_title='Scaled Values',
233
+ template='plotly_white'
234
+ )
235
  st.plotly_chart(fig, use_container_width=True)
236
  elif data_type == "Price":
237
+ # Plot Modal Price
238
  import plotly.graph_objects as go
239
  fig = go.Figure()
240
+ fig.add_trace(go.Scatter(
241
+ x=df_grouped['Reported Date'],
242
+ y=df_grouped['Modal Price (Rs./Quintal)'],
243
+ mode='lines',
244
+ name='Modal Price',
245
+ line=dict(width=1, color='green')
246
+ ))
247
  fig.update_layout(title="Modal Price Trend", xaxis_title='Date', yaxis_title='Price (/Quintall)', template='plotly_white')
248
  st.plotly_chart(fig, use_container_width=True)
249
+ elif data_type == "Volume":
250
+ # Plot Arrivals (Tonnes)
251
  import plotly.graph_objects as go
252
  fig = go.Figure()
253
+ fig.add_trace(go.Scatter(
254
+ x=df_grouped['Reported Date'],
255
+ y=df_grouped['Arrivals (Tonnes)'],
256
+ mode='lines',
257
+ name='Arrivals',
258
+ line=dict(width=1, color='blue')
259
+ ))
260
  fig.update_layout(title="Arrivals Trend", xaxis_title='Date', yaxis_title='Volume (in Tonnes)', template='plotly_white')
261
  st.plotly_chart(fig, use_container_width=True)
262
  else: