How to append daily data?

I have the previous 365 days of data stored in 'Daily API Download Master.csv'. I wish to daily append this file with new data. However no data is being appended with the below code. How might I get this to work?
#import packages
import eikon as ek # the Eikon Python wrapper package
import pandas as pd
import numpy as np
import datetime
from datetime import timedelta, date, datetime
from pandas.tseries.offsets import BDay
#connects to Bill's Eikon terminal
ek.set_app_key('x')
#retreive RICs
df_rics,e = ek.get_data("lists('Inv Trust List')","TR.RIC")
ric_list = df_rics['Instrument'].tolist()
#Slice, loop and concatenate the retrieval request
n = 50
df = pd.DataFrame()
for ric_chunk in [ric_list[i:i + n]
for i in range(0, len(ric_list), n)]:
tmp_df, e = ek.get_data(ric_chunk,
['TR.RNSFilerName',
'TR.RNSAnnouncedDate',
'TR.RNSTransactionType',
'TR.RNSARNumShrsTransacted',
'TR.RNSARPctOSTransacted',
'TR.RNSARTransactionPrice',
'TR.RNSARMktValTransaction',
'TR.RNSARTotShrsPostTrans',
'TR.RNSARPctOSPostTrans'])
df = tmp_df.append(df)
#set boundary dates - previous business day
end_date = date.today()
start_date = end_date - BDay(1)
#string format dates
end_date_str = datetime.strftime(end_date, "%Y-%m-%d")
start_date_str = datetime.strftime(start_date, "%Y-%m-%d")
#datetime formatting
df['RNS Announced Date'] = pd.to_datetime(df['RNS Announced Date'])
#set date constraints as object
mask = (df['RNS Announced Date'] > start_date_str) & (df['RNS Announced Date'] <= end_date_str)
#reset dataframe for boundary dates
df = df.loc[mask]
#rename '£' symbol
df.rename(columns={'RNS AR Price (at Transaction) - £': 'RNS AR Price (at Transaction) GBP',
'RNS AR Market Value of Transaction - £': 'RNS AR Market Value of Transaction - GBP'},
inplace=True)
#append new data to the the master csv
df.to_csv('Daily API Download Master.csv', mode='a', header=False)
Best Answer
-
I think the problem is in your filtering logic by announcement date. The data you retrieve is not real-time. The most recent announcement date in the result set will be yesterday's date. Yet your logic filters out all records with announcement date less than today. I think you need to include the records with announcement date of yesterday, e.g. as follows
mask = ((df['RNS Announced Date'] >= start_date) &
(df['RNS Announced Date'] <= end_date))Note that compared to your code I'm including records where the announcement date equals start_date.
0
Answers
-
Hi @bill39
fields = ['TR.RNSFilerName','TR.RNSAnnouncedDate','TR.RNSTransactionType','TR.RNSARNumShrsTransacted',
'TR.RNSARPctOSTransacted','TR.RNSARTransactionPrice','TR.RNSARMktValTransaction','TR.RNSARTotShrsPostTrans','TR.RNSARPctOSPostTrans']
df1,e = ek.get_data('TSCO.L',fields)
df2,e = ek.get_data('VOD.L',fields)
df1.to_csv('test1.csv', mode = 'a', header = False)
df2.to_csv('test1.csv', mode = 'a', header = False)And I got both results append in test1.csv file
0
Categories
- All Categories
- 3 Polls
- 6 AHS
- 36 Alpha
- 166 App Studio
- 6 Block Chain
- 4 Bot Platform
- 18 Connected Risk APIs
- 47 Data Fusion
- 34 Data Model Discovery
- 685 Datastream
- 1.4K DSS
- 616 Eikon COM
- 5.2K Eikon Data APIs
- 10 Electronic Trading
- Generic FIX
- 7 Local Bank Node API
- 3 Trading API
- 2.9K Elektron
- 1.4K EMA
- 252 ETA
- 557 WebSocket API
- 38 FX Venues
- 14 FX Market Data
- 1 FX Post Trade
- 1 FX Trading - Matching
- 12 FX Trading – RFQ Maker
- 5 Intelligent Tagging
- 2 Legal One
- 23 Messenger Bot
- 3 Messenger Side by Side
- 9 ONESOURCE
- 7 Indirect Tax
- 60 Open Calais
- 275 Open PermID
- 44 Entity Search
- 2 Org ID
- 1 PAM
- PAM - Logging
- 6 Product Insight
- Project Tracking
- ProView
- ProView Internal
- 22 RDMS
- 1.9K Refinitiv Data Platform
- 653 Refinitiv Data Platform Libraries
- 4 LSEG Due Diligence
- LSEG Due Diligence Portal API
- 4 Refinitiv Due Dilligence Centre
- Rose's Space
- 1.2K Screening
- 18 Qual-ID API
- 13 Screening Deployed
- 23 Screening Online
- 12 World-Check Customer Risk Screener
- 1K World-Check One
- 46 World-Check One Zero Footprint
- 45 Side by Side Integration API
- 2 Test Space
- 3 Thomson One Smart
- 10 TR Knowledge Graph
- 151 Transactions
- 143 REDI API
- 1.8K TREP APIs
- 4 CAT
- 27 DACS Station
- 121 Open DACS
- 1.1K RFA
- 104 UPA
- 193 TREP Infrastructure
- 229 TRKD
- 917 TRTH
- 5 Velocity Analytics
- 9 Wealth Management Web Services
- 90 Workspace SDK
- 11 Element Framework
- 5 Grid
- 18 World-Check Data File
- 1 Yield Book Analytics
- 46 中文论坛