How do I get the data frame index as an array?
Do you know how to get the index column of an dataframe as an array? I have a list of accession numbers in the "Accession" column of a CSV file, which I imported into Pandas, and during the import, I set the index to the "Accession" column. Now, I need the "Accession" column to be a set of labels in a later step, but I don't know how to extract it standalone.
You should use the
In : df = pd.DataFrame(index=['a', 'b']) In : df.index.values Out: array(['a', 'b'], dtype=object)
This accesses how the data is already stored, so there's no need for a conversion.
Note: This attribute is also available for many other pandas' objects.