Intraday Stock Data Viewer App
Below is a simple Python application using the pandas library to read the CSV file and matplotlib to display the intraday stock data.
Requirements
- Python 3.8+
- pandas
- matplotlib
Installation
To install the required libraries, run the following command:
pip install pandas matplotlib
Code
import pandas as pd
import matplotlib.pyplot as plt
def load_data(file_path):
"""Load intraday stock data from a CSV file."""
try:
data = pd.read_csv(file_path)
data['Date'] = pd.to_datetime(data['Date'])
data.set_index('Date', inplace=True)
return data
except Exception as e:
print(f"Error loading data: {e}")
return None
def plot_data(data):
"""Plot the intraday stock data."""
plt.figure(figsize=(12, 6))
plt.plot(data.index, data['Close'])
plt.title('Intraday Stock Data')
plt.xlabel('Time')
plt.ylabel('Price')
plt.grid(True)
plt.show()
def main():
file_path = input("Enter the CSV file path: ")
data = load_data(file_path)
if data is not None:
print(data.head())
plot_data(data)
if __name__ == "__main__":
main()
Usage
- Save the above code in a file named
intraday_viewer.py.
- Run the application using
python intraday_viewer.py.
- Enter the path to your CSV file when prompted.
- The application will display the first few rows of the data and plot the intraday stock data.
CSV File Format
The CSV file should have the following format:
Date,Open,High,Low,Close,Volume
2022-01-01 09:30:00,100.0,100.5,99.5,100.2,1000
2022-01-01 09:31:00,100.2,100.7,99.7,100.5,1200
2022-01-01 09:32:00,100.5,101.0,100.0,100.8,1500
...
Note: The Date column should be in the format YYYY-MM-DD HH:MM:SS. The Open, High, Low, Close, and Volume columns should contain the corresponding stock data values.