I have two data frames, the first represent share prices and the second represent the company names. When I try to merge them on a unique key, which is SimFinId, everything is fine except that I lose the Ticker and the Date columns from the share prices table. I need to keep those two columns on every merge -I want later also to merge the output with a third table -so I can later filter after the date. I'm using Jupyter. Any help will be much appreciated!
pip install simfin
# Import the main functionality from the SimFin Python API.
import simfin as sf
# Import names used for easy access to SimFin's data-columns.
from simfin.names import *
import datetime
# Set your API-key for downloading data. This key gets the free data.
sf.set_api_key('free')
# Set the local directory where data-files are stored.
# The directory will be created if it does not already exist.
sf.set_data_dir('~/simfin_data/')
# Download the data from the SimFin server and load into a Pandas DataFrame.
df_prices = sf.load_shareprices(variant='daily', market='us', index=[TICKER, DATE])
Thats the share prices table
SimFinId Open Low High Close Adj. Close Dividend \
Ticker Date
A 2007-01-03 45846 34.99 34.05 35.48 34.30 22.66 NaN
2007-01-04 45846 34.30 33.46 34.60 34.41 22.73 NaN
2007-01-05 45846 34.30 34.00 34.40 34.09 22.52 NaN
2007-01-08 45846 33.98 33.68 34.08 33.97 22.44 NaN
2007-01-09 45846 34.08 33.63 34.32 34.01 22.47 NaN
Volume Shares Outstanding
Ticker Date
A 2007-01-03 2574600 NaN
2007-01-04 2073700 NaN
2007-01-05 2676600 NaN
2007-01-08 1557200 NaN
2007-01-09 1386200 NaN
# Download the companies data from the SimFin server and load into a Pandas DataFrame.
df_companies = sf.load_companies(market='us', index=[TICKER])
Thats the company name table
SimFinId Company Name IndustryId
Ticker
A 45846 AGILENT TECHNOLOGIES INC 106001.0
AA 367153 Alcoa Corp 110004.0
AAC_delist 939324 AAC Holdings, Inc. 106011.0
AAL 68568 American Airlines Group Inc. 100006.0
AAMC 847094 Altisource Asset Management Corp 104001.0
# Merging the share prices Data with the companies Data on SimFinId.
pd.merge(df_companies, df_prices, on='SimFinId')