Home > OS >  Can't extract the data out of the tuple while using the get data eikon package with the refinit
Can't extract the data out of the tuple while using the get data eikon package with the refinit

Time:12-23

# Use the Data Item Browser to find the name of the TR
## Manually calculate the PE

   test = ek.get_data(['IBM','AAPL.O'],['TR.DPSmean','TR.PriceClose'])
   test

OUTPUT

  Out[36]: 
  (  Instrument  Dividend Per Share - Mean  Price Close
 0        IBM                      6.675       140.88
 1     AAPL.O                    0.97507       132.23,
 None)

Here is where I retrieve the infos. What I want to do is just simply divide the Price close by the dividend per share But every time I get a tuple error, whether I just want to print or divide

I tryed every solution that chatgpt proposed me including the pandas package, the index solution and some others but every time it is a tuple problem

CodePudding user response:

I'm assuming the first element in the tuple is a dataframe, so:

df = test[0]
df["Result"] = df["Price Close"] / df["Dividend Per Share - Mean"]

print(df)

Prints:

  Instrument  Dividend Per Share - Mean  Price Close      Result
0        IBM                    6.67500       140.88   21.105618
1     AAPL.O                    0.97507       132.23  135.610777
  • Related