# Is there a way to use the astropy table indicies in the same way as Pandas dataframe indicies?

**URL:** <https://community.openastronomy.org/t/is-there-a-way-to-use-the-astropy-table-indicies-in-the-same-way-as-pandas-dataframe-indicies/470>\
**Category:** Astropy\
**Tags:** astropy, table, question\
**Created:** [October 7, 2022, 2:56pm UTC](https://community.openastronomy.org/t/is-there-a-way-to-use-the-astropy-table-indicies-in-the-same-way-as-pandas-dataframe-indicies/470 "2022-10-07T14:56:08Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![SpaceMetallicFox](https://dub1.discourse-cdn.com/flex005/user_avatar/community.openastronomy.org/spacemetallicfox/32/285_2.png) [@SpaceMetallicFox](https://community.openastronomy.org/u/SpaceMetallicFox)\
**Post date:** [October 7, 2022, 2:56pm UTC](https://community.openastronomy.org/t/is-there-a-way-to-use-the-astropy-table-indicies-in-the-same-way-as-pandas-dataframe-indicies/470/1 "2022-10-07T14:56:08Z")

</div>

If I have some dataframe with indicies and if I need to slice it, indicies will be still in the sliced dataframe, whereas in astropy I didn’t find anything similar. I saw that there are also some indicies, but, if I got it right, they’re different and they’re not transferred in a sliced table (for example, if one chooses several columns from the main table).

---

<div class="post-metadata">

**Author:** ![hamogu](https://dub1.discourse-cdn.com/flex005/user_avatar/community.openastronomy.org/hamogu/32/93_2.png) [@hamogu](https://community.openastronomy.org/u/hamogu)\
**Post date:** [October 10, 2022, 12:30am UTC](https://community.openastronomy.org/t/is-there-a-way-to-use-the-astropy-table-indicies-in-the-same-way-as-pandas-dataframe-indicies/470/2 "2022-10-10T00:30:44Z")

</div>

It depends on what exactly you try to accomplish. If you just want to keep an index in your table that stays around, the easiest is probably to make a new index column:

```auto
tab = Table.read('abcd.fits')
tab['index'] = np.arange(len(table))

```

Then, that’s just a normal table column and when you slice and dice the table, the index will stay with each row.

---

<div class="post-metadata">

**Author:** ![SpaceMetallicFox](https://dub1.discourse-cdn.com/flex005/user_avatar/community.openastronomy.org/spacemetallicfox/32/285_2.png) [@SpaceMetallicFox](https://community.openastronomy.org/u/SpaceMetallicFox)\
**Post date:** [October 10, 2022, 4:35pm UTC](https://community.openastronomy.org/t/is-there-a-way-to-use-the-astropy-table-indicies-in-the-same-way-as-pandas-dataframe-indicies/470/3 "2022-10-10T16:35:19Z")

</div>

Actually, I just wanted to use astropy tables as the arguments for “sklearn.model\_selection.train\_test\_split” function, but there is a problem because the tables are not indexed. Therefore, I can’t use them instead of pandas dataframes.

---

<div class="post-metadata">

**Author:** ![dhomeier](https://dub1.discourse-cdn.com/flex005/user_avatar/community.openastronomy.org/dhomeier/32/65_2.png) [@dhomeier](https://community.openastronomy.org/u/dhomeier)\
**Post date:** [November 14, 2022, 3:22pm UTC](https://community.openastronomy.org/t/is-there-a-way-to-use-the-astropy-table-indicies-in-the-same-way-as-pandas-dataframe-indicies/470/4 "2022-11-14T15:22:18Z")

</div>

Can you post details of the error you are seeing, i.e. what property is `sklearn` trying to access?
