In this PyQt5 article we want to learn How to Integrate Yahoo Finance API with PyQt5, PyQt5 is powerful Python library for building desktop applications with graphical user interface. Yahoo Finance API is popular platform for accessing financial data such as stock prices, news and analysis. integrating Yahoo Finance API with PyQt5 can be great way to add financial data to your PyQt5 application. in this article we want to talk how to integrate Yahoo Finance with PyQt5.
First of all we need to install required libraries
1 |
pip install pandas yfinance |
Now this is the complete code for this article
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
import sys import yfinance as yf from PyQt5.QtWidgets import QApplication, QMainWindow, QTableView, QWidget, QVBoxLayout from PyQt5.QtGui import QStandardItem, QStandardItemModel class FinanceApp(QWidget): def __init__(self): super().__init__() self.setWindowTitle("Geekscoders.com - Finance App") self.table = QTableView() layout = QVBoxLayout() layout.addWidget(self.table) self.setLayout(layout) # Retrieve data from Yahoo Finance aapl = yf.Ticker('AAPL') data = aapl.history(period='1mo') # Load data into QTableView widget model = QStandardItemModel(data.shape[0], data.shape[1]) model.setHorizontalHeaderLabels(data.columns) for row in range(data.shape[0]): for column in range(data.shape[1]): item = QStandardItem(str(data.iloc[row, column])) model.setItem(row, column, item) self.table.setModel(model) if __name__ == '__main__': app = QApplication(sys.argv) window = FinanceApp() window.show() sys.exit(app.exec_()) |
In this code we have used QStandardItemModel class to load the data into the QTableView widget. we first creates QStandardItemModel object with the same number of rows and columns as the DataFrame, and set the horizontal header labels to the DataFrame column names. we then loop through each cell in the DataFrame and set the corresponding cell in the QStandardItemModel object with the cell value.
If you run the code this will be the result
Learn More on PyQt5
- How to Deploy PyQt5 Applications
- How to Integrate PyQt5 with OpenCV
- How to Use Stylesheets in PyQt5
- Learn PyQt5 Event Handling with Signals and Slots
- PyQt5 Tutorial: Creating Menus and Toolbars
- How to Open & Save Files in Python PyQt5
- PyQt5 Designer Tutorial: Complete Guide to Qt Designer
- PyQt5 vs Tkinter: Which GUI Library is Right for You
- How to Build Web Applications in PyQt5
- How to Integrate Python Flask with PyQt5