Discover Refinitiv
MyRefinitiv Refinitiv Perspectives Careers
Created with Sketch.
All APIs Questions & Answers  Register |  Login
Ask a question
  • Questions
  • Tags
  • Badges
  • Unanswered
Search:
  • Home /
  • Eikon Data APIs /
avatar image
Question by CT1309 · Oct 09, 2017 at 02:23 AM · historical dataforecast datamerge dataframe

Merging historical and forecast dataframe yields duplicates

I get duplicate cells when I merge two dataframes: one containing historical data, a second containing forecast data, as follows:

tkrrenew = ['0916.HK', '0958.HK', '0451.HK', '1798.HK']
fdflds = ['CF_NAME', 'TR.EBITDA.rfperiod', 'TR.BasicEpsExclExtraItems.Currency', 'TR.BasicEpsExclExtraItems', 'TR.DpsCommonStock']
param = {'Period': 'FY0', 'SDate': 'FY-2', 'EDate': 'FY0', 'FRQ': 'FY'}
valrenew, err = ek.get_data(tkrrenew, fdflds, param)


frcstfld = ['CF_NAME', 'TR.EPSSmartEst.rfperiod', 'TR.EPSSmartEst', 'TR.DPSMean']
paramfcst = {'Period': 'FY1', 'SDate': '0', 'EDate': '2', 'FRQ': 'FY'}
fcstrenew, err = ek.get_data(tkrrenew, frcstfld, paramfcst)

testrenew = valrenew.merge(fcstrenew, on=['Instrument', 'Name'], how='inner')

The output, after some other commands is as follows:

Apart from .drop_duplicate(subset=['Instrument', 'FY']) which leaves me with:

What can I do to have both historical and forecast data till FY3 in one dataframe. If .join or .append can place the FY1-FY3 in the same column as FY-2 to FY0, that would ideal.

Pls advise.

eikon.png (29.1 KiB)
eikon2.png (21.2 KiB)

People who like this

0 Show 0
Comment
10 |1500 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

2 Replies

  • Sort: 
avatar image
REFINITIV
Best Answer
Answer by Alex Putkov. · Oct 20, 2017 at 01:12 PM

Is this what you're looking for?
valrenew.merge(fcstrenew, on=['Instrument', 'Financial Period Relative' ], how='outer')
This will give you


You can then sort the resulting dataframe on Instrument and then Financial Period Relative column to get chronological view grouped by the stock. You can remove duplicate CF_NAME column (CF_NAME_x or CF_NAME_y), or you can drop CF_NAME field from one of the requests.


mergeddataframe.png (44.1 KiB)
Comment

People who like this

0 Show 0 · Share
10 |1500 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

avatar image
Answer by CT1309 · Oct 31, 2017 at 09:32 AM

Thanks, Alex & Wasin.

I've rewritten my code such that it now goes as follows:

dffrkFY0 = dffrank[dffrank.FY == 'FY0'] #extract FY0 data
dffrkFY1 = dffrank[dffrank.FY == 'FY-1'] #extract FY-1 data
dffrkFY1.columns = [['Instrument', 'Name', 'FYE', 'RpCrncy','EstEPS','EstDPS','EstBVPS','PxCrncy','Price',\
                     'FXCode', 'FXRate', 'EstPER', 'EstPB', 'EstD_Yld']]

# dffwd is an earlier DataFrame

dffmerge = pd.concat([dffwd, dffrkFY0, dffrkFY1], join='inner')
dffmerge = dffmerge.sort_values(['Instrument', 'FYE'])
dffmerge = dffmerge.reset_index(drop=True)
dffmerge[:15]

Thanks for your effort; much appreciated.

Later on in the code, I re-jig the <Name> such that it doesn't appear at such an odd position.


dtframe.png (39.1 KiB)
Comment

People who like this

0 Show 0 · Share
10 |1500 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Watch this question

Add to watch list
Add to your watch list to receive emailed updates for this question. Too many emails? Change your settings >
9 People are following this question.

Related Questions

How can I get the historical options greeks and implied volatility ?

Using API to pull the historical index constituents during a period of time

Which Eikon API is best suite for pulling Real time and Historical data?

Historical Estimates

Can the historic derived holdings for a fund be accessed through the API?

  • Feedback
  • Copyright
  • Cookie Policy
  • Privacy Statement
  • Terms of Use
  • Careers
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Alpha
  • App Studio
  • Block Chain
  • Bot Platform
  • Calais
  • Connected Risk APIs
  • DSS
  • Data Fusion
  • Data Model Discovery
  • Datastream
  • Eikon COM
  • Eikon Data APIs
  • Elektron
    • EMA
    • ETA
    • WebSocket API
  • Legal One
  • Messenger Bot
  • Messenger Side by Side
  • ONESOURCE
    • Indirect Tax
  • Open PermID
    • Entity Search
  • Org ID
  • PAM
    • PAM - Logging
  • ProView
  • ProView Internal
  • Product Insight
  • Project Tracking
  • Refinitiv Data Platform
    • Refinitiv Data Platform Libraries
  • Rose's Space
  • Screening
    • Qual-ID API
    • Screening Deployed
    • Screening Online
    • World-Check One
    • World-Check One Zero Footprint
  • Side by Side Integration API
  • TR Knowledge Graph
  • TREP APIs
    • CAT
    • DACS Station
    • Open DACS
    • RFA
    • UPA
  • TREP Infrastructure
  • TRIT
  • TRKD
  • TRTH
  • Thomson One Smart
  • Transactions
    • REDI API
  • Velocity Analytics
  • Wealth Management Web Services
  • World-Check Data File
  • Explore
  • Tags
  • Questions
  • Badges