Search code examples
pythonarrayscsvidl-programming-language

Import Only Necessary CSV Columns In IDL


I am struggling to find a function in IDL that will replicate something I have done in Python with Pandas. I am new to IDL and there is next to nothing resource wise that I can find.

In Python, I use the following:

pd.read_csv('<csv filepath>', usecols=[n])

The usecols part will only pull in the columns of a CSV I would like in my data frame. Is there a way to do this in IDL?

I hope this makes sense - my first post here!

Thanks.


Solution

  • There is a READ_CSV routine that can read CSV files, but it does not have a way to pull out specific columns. It will give you a structure with one field for each column of the CSV file — so you could just grab the column you need from the structure and throwing away the rest of the structure. Something like:

    csv = read_csv('somefile.csv')
    col_n = csv.(n)