How can I fix my “Empty DataFrame” error?

I am working on a project where I’m trying to create an algorithmic trading module with python. I intend to experiment with real-time market data obtained from the Alpha Vantage website via a free API Key/Token however, even though I’m able to make the initial API call & parse the API call, I am unable to add the stocks data to a pandas dataframe via append method.

My code:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code># Import necessary libraries
import pandas as pd
import requests
# Unused libraries so far
"""import numpy as np
import pandas as pd
import xlsxwriter
import math"""
# Acquiring an API Token
# Free API Token/Key can be easily acquired here >>> https://www.alphavantage.co/support/#api-key
API_key = ''
# S&P 500 stocks List in CSV Format >>> for later use in the project
# ***stocks = pd.read_csv('sp_500_stocks.csv')
# Making the API call
symbol = 'AAPL'
api_url = f'https://www.alphavantage.co/query?function=GLOBAL_QUOTE&symbol={symbol}&apikey={API_key}'
data = requests.get(api_url).json()
# print(data['Global Quote']['06. volume'])
# Parsing the API call
# symbol = data['Global Quote']['01. symbol']
price = data['Global Quote']['05. price']
volume = data['Global Quote']['06. volume']
# Adding the stocks data to a pandas DataFrame
my_columns = ['Ticker', 'Stock Price', 'Market Volume', 'Number of Shares to Buy'] # Number of Shares to Buy is to be calculated later in the project
final_dataFrame = pd.DataFrame(columns=my_columns)
print(final_dataFrame)
# Append method
final_dataFrame._append( # *** START HERE<<<<<<<<
pd.Series(
[
symbol,
price,
volume,
'N/A' # To be calculated later in the project
],
index=my_columns
),
ignore_index=True
)
</code>
<code># Import necessary libraries import pandas as pd import requests # Unused libraries so far """import numpy as np import pandas as pd import xlsxwriter import math""" # Acquiring an API Token # Free API Token/Key can be easily acquired here >>> https://www.alphavantage.co/support/#api-key API_key = '' # S&P 500 stocks List in CSV Format >>> for later use in the project # ***stocks = pd.read_csv('sp_500_stocks.csv') # Making the API call symbol = 'AAPL' api_url = f'https://www.alphavantage.co/query?function=GLOBAL_QUOTE&symbol={symbol}&apikey={API_key}' data = requests.get(api_url).json() # print(data['Global Quote']['06. volume']) # Parsing the API call # symbol = data['Global Quote']['01. symbol'] price = data['Global Quote']['05. price'] volume = data['Global Quote']['06. volume'] # Adding the stocks data to a pandas DataFrame my_columns = ['Ticker', 'Stock Price', 'Market Volume', 'Number of Shares to Buy'] # Number of Shares to Buy is to be calculated later in the project final_dataFrame = pd.DataFrame(columns=my_columns) print(final_dataFrame) # Append method final_dataFrame._append( # *** START HERE<<<<<<<< pd.Series( [ symbol, price, volume, 'N/A' # To be calculated later in the project ], index=my_columns ), ignore_index=True ) </code>
# Import necessary libraries

import pandas as pd
import requests

# Unused libraries so far

"""import numpy as np
import pandas as pd
import xlsxwriter
import math"""

# Acquiring an API Token
# Free API Token/Key can be easily acquired here >>> https://www.alphavantage.co/support/#api-key

API_key = ''

# S&P 500 stocks List in CSV Format >>> for later use in the project

# ***stocks = pd.read_csv('sp_500_stocks.csv')

# Making the API call

symbol = 'AAPL'
api_url = f'https://www.alphavantage.co/query?function=GLOBAL_QUOTE&symbol={symbol}&apikey={API_key}'
data = requests.get(api_url).json()
# print(data['Global Quote']['06. volume'])

# Parsing the API call

# symbol = data['Global Quote']['01. symbol']
price = data['Global Quote']['05. price']
volume = data['Global Quote']['06. volume']

# Adding the stocks data to a pandas DataFrame

my_columns = ['Ticker', 'Stock Price', 'Market Volume', 'Number of Shares to Buy'] # Number of Shares to Buy is to be calculated later in the project
final_dataFrame = pd.DataFrame(columns=my_columns)
print(final_dataFrame)

# Append method

final_dataFrame._append(  # *** START HERE<<<<<<<<
    pd.Series(
        [
            symbol,
            price,
            volume,
            'N/A' # To be calculated later in the project
        ],
        index=my_columns
    ),
    ignore_index=True
) 

I tried the above code & it returns the following:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>Empty DataFrame
Columns: [Ticker, Stock Price, Market Volume, Number of Shares to Buy]
Index: []
</code>
<code>Empty DataFrame Columns: [Ticker, Stock Price, Market Volume, Number of Shares to Buy] Index: [] </code>
Empty DataFrame
Columns: [Ticker, Stock Price, Market Volume, Number of Shares to Buy]
Index: []

The output should be a table showing the my_columns list and the corresponding data for each coliumn on the rows.

New contributor

Samson is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật