I have an excel file containing a companies/employee names, their patent applications and year of filing. However, now I need the financial information for these firms for the given year (from eikon), as listed in the excel sheet. The main problem i have is that the names in the excel sheet are not an exact match with Eikon (no RIC, PermID, or any other corresponding code). How do I work around this.
Here is an extract of my current code:
import eikon as tr
import pandas as pd
resulttable_df = pd.read_excel(r'C:\xxxxx\resulttable.xlsx')
def get_financial_data(company, year):
# Example: fetching market cap for a given company (RIC) and year
fields = ['TR.MktCap']
response = tr.get_data([company], fields=fields, raw_output=True)
if 'data' in response and response['data']:
for item in response['data']:
if 'data' in item:
financial_data_list = item['data']
for data_item in financial_data_list:
if 'field' in data_item and data_item['field'] == 'TR.MktCap':
return data_item.get('value', None)
return None
# Iterate over rows in the "resulttable" dataset and fetch financial data
for index, row in resulttable_df.iterrows():
company = row['person_name']
year = row['appln_filing_year']
financial_data = get_financial_data(company, year)
# Print or process the financial data as needed
if financial_data is not None:
print(f"For {company} in {year}, Market Cap: {financial_data}")
else:
print(f"No financial data found for {company} in {year}")