简体   繁体   中英

pandas.DataFrame - get the UID of each row?

After using yfinance.download() , I result in a pandas.DataFrame object, that, when printed, outputs to this:

Date                                                                                    
2018-01-02  18700.199219  18700.199219  18700.199219  18700.199219  18700.199219       0
2018-01-03  18953.099609  18953.099609  18953.099609  18953.099609  18953.099609       0
2018-01-04  18922.500000  18922.500000  18922.500000  18922.500000  18922.500000       0
2018-01-05  18849.800781  18849.800781  18849.800781  18849.800781  18849.800781       0
2018-01-08  18911.900391  18911.900391  18911.900391  18911.900391  18911.900391       0
...                  ...           ...           ...           ...           ...     ...
2022-03-04  23165.710938  23165.710938  23165.710938  23165.710938  23165.710938       0
2022-03-07  23148.070312  23148.070312  23148.070312  23148.070312  23148.070312       0
2022-03-08  23026.910156  23026.910156  23026.910156  23026.910156  23026.910156       0
2022-03-09  22659.669922  22659.669922  22659.669922  22659.669922  22659.669922       0
2022-03-10  22437.609375  22437.609375  22437.609375  22437.609375  22437.609375       0

[1061 rows x 6 columns]

I called it the UID since it is a unique identifier (Ie special for each row) and it does not get classified as an column.

How do I access the data from the "Date" column?

How do I access the data from the "Date" column?

Reset the index first, and convert the index to a regular column:

df.reset_index()['Date']

OR, keep Date column as your index and simply get the index column:

df.index

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM