Upgrade from Eikon -> Workspace. Learn about programming differences.

For a deeper look into our Eikon Data API, look into:

Overview |  Quickstart |  Documentation |  Downloads |  Tutorials |  Articles

question

Upvotes
Accepted
5 4 2 6

How to import a list of RICs from csv file, then use it in ek.get_data

I have been trying to import a list of Cusips from csv file, but then I want to use it in ek.get_data funtion insted of using a list of cusips. This is the code I have so far :

I want to do this :

data_grid, err = ek.get_data([CUSIPS], ['DSPLY_NAME','OFFCL_CODE',.....]

Where CUSIPS is a csv file

insted of this:

data_grid, err = ek.get_data(['USFN3025=RR', 'USFN3030=RR'],['OFFCL_CODE','DSPLY_NAME'])

Thanks,


eikoneikon-data-apipythonrefinitiv-dataplatform-eikonworkspaceworkspace-data-apidata
icon clock
10 |1500

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

Upvotes
Accepted
17k 80 39 63

Hi @GABRIEL.ESQUIVEL,

There are a couple of things within your code segment above:

1. You are not creating an array of items, but an array of rows of data. You will have to loop through each row to pull out the item.

2. When you call get_data(), instead of this:

ek.get_data(["instrument"], ...)

you need to do this:

eg.get_data(instrument, ...)

All you are doing above is passing in an array containing the value "instrument". The variable you created above called instrument is an array and you simply need to pass that in.

Here is a code sample that works for me. Note: you can see I'm looping through each row and pulling out item:


ahs.png (14.0 KiB)
icon clock
10 |1500

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

Upvotes
17k 80 39 63

Hi @GABRIEL.ESQUIVEL,

The get_data() function does not accept a file as input. You will have to import your file into an array and provide that as input. Because CSV files can contain whatever you want, comments, blank lines, etc, it is more conducive for the developer to parse the file themselves. You can likely find numerous examples on the internet such as this one. If you have more complex layouts within your CSV file, the pandas read_csv may be useful.

In either case, it is a few extra lines of code.

icon clock
10 |1500

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

Upvotes
5 4 2 6

Yes, you're right but how I introduce this array into the funtion?

I doing the following:

instrument = []

with open('CUSIPS - NONEST.csv') as csvDataFile:
csvReader = csv.reader(csvDataFile)
for row in csvReader:
instrument.append(row[0])

print(instrument)

then,

Prices_NonEstrutured, err = ek.get_data(["instrument"],
['OFFCL_CODE','DSPLY_NAME'])
Prices_NonEstrutured.head()

But of course this wont work

Thank you @nick.zincone.1


icon clock
10 |1500

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

Upvotes
5 4 2 6

Hi @nick. These was very helpful, thank you so much for you're time :)

icon clock
10 |1500

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

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

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