Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,12 @@
# Don't delete this repo!
Based on the assumptions, we will need the following core functions:

1. `load_data`: This function will load the Google stock price data from the CSV file using pandas.
2. `plot_line_chart`: This function will plot a line chart of the stock prices over time using matplotlib.
3. `plot_histogram`: This function will plot a histogram of the volume of stocks traded using matplotlib.
4. `display_statistics`: This function will display statistical analysis of the stock prices.

The entry point of the application will be `app.py`, which will contain the main logic of the Streamlit app.

Let's start with the `app.py` file:

app.py
76 changes: 76 additions & 0 deletions all_output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
Based on the assumptions, we will need the following core functions:

1. `load_data`: This function will load the Google stock price data from the CSV file using pandas.
2. `plot_line_chart`: This function will plot a line chart of the stock prices over time using matplotlib.
3. `plot_histogram`: This function will plot a histogram of the volume of stocks traded using matplotlib.
4. `display_statistics`: This function will display statistical analysis of the stock prices.

The entry point of the application will be `app.py`, which will contain the main logic of the Streamlit app.

Let's start with the `app.py` file:

app.py
```python
import streamlit as st
import pandas as pd
import matplotlib.pyplot as plt

# Load data
@st.cache
def load_data():
df = pd.read_csv('google_stock_price.csv')
df['Date'] = pd.to_datetime(df['Date'])
return df

# Plot line chart
def plot_line_chart(df, start_date, end_date):
df = df[(df['Date'] >= start_date) & (df['Date'] <= end_date)]
plt.figure(figsize=(12,6))
plt.plot(df['Date'], df['Close'])
plt.title('Google Stock Prices Over Time')
plt.xlabel('Date')
plt.ylabel('Close Price')
st.pyplot()

# Plot histogram
def plot_histogram(df):
plt.figure(figsize=(12,6))
plt.hist(df['Volume'], bins=30, alpha=0.75)
plt.title('Histogram of Volume of Stocks Traded')
plt.xlabel('Volume')
plt.ylabel('Frequency')
st.pyplot()

# Display statistics
def display_statistics(df):
st.write(df.describe())

def main():
df = load_data()

st.title('Google Stock Price Analysis')

start_date = st.date_input('Start date', df['Date'].min())
end_date = st.date_input('End date', df['Date'].max())

if start_date > end_date:
st.error('Error: End date must fall after start date.')
else:
plot_line_chart(df, start_date, end_date)
plot_histogram(df)
display_statistics(df)

if __name__ == "__main__":
main()
```

The `requirements.txt` file will contain the necessary Python packages:

requirements.txt
```txt
streamlit
pandas
matplotlib
```

This Streamlit app can be run using the command `streamlit run app.py`. The app will display a line chart of Google's stock prices over the selected date range, a histogram of the volume of stocks traded, and statistical analysis of the stock prices.
51 changes: 51 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import streamlit as st
import pandas as pd
import matplotlib.pyplot as plt

# Load data
@st.cache
def load_data():
df = pd.read_csv('google_stock_price.csv')
df['Date'] = pd.to_datetime(df['Date'])
return df

# Plot line chart
def plot_line_chart(df, start_date, end_date):
df = df[(df['Date'] >= start_date) & (df['Date'] <= end_date)]
plt.figure(figsize=(12,6))
plt.plot(df['Date'], df['Close'])
plt.title('Google Stock Prices Over Time')
plt.xlabel('Date')
plt.ylabel('Close Price')
st.pyplot()

# Plot histogram
def plot_histogram(df):
plt.figure(figsize=(12,6))
plt.hist(df['Volume'], bins=30, alpha=0.75)
plt.title('Histogram of Volume of Stocks Traded')
plt.xlabel('Volume')
plt.ylabel('Frequency')
st.pyplot()

# Display statistics
def display_statistics(df):
st.write(df.describe())

def main():
df = load_data()

st.title('Google Stock Price Analysis')

start_date = st.date_input('Start date', df['Date'].min())
end_date = st.date_input('End date', df['Date'].max())

if start_date > end_date:
st.error('Error: End date must fall after start date.')
else:
plot_line_chart(df, start_date, end_date)
plot_histogram(df)
display_statistics(df)

if __name__ == "__main__":
main()
3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
streamlit
pandas
matplotlib
3 changes: 3 additions & 0 deletions run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pip install -r requirements.txt

streamlit run app.py