Home  >  Article  >  Backend Development  >  How to Convert Pandas Series or Index to NumPy Array?

How to Convert Pandas Series or Index to NumPy Array?

DDD
DDDOriginal
2024-10-20 15:49:02144browse

How to Convert Pandas Series or Index to NumPy Array?

Converting Pandas Series or Index to NumPy Array

Retrieving a Pandas series or index as a NumPy array is straightforward using the values attribute. This attribute provides direct access to the underlying data without the need for conversion.

To obtain a NumPy array of the index:

This attribute is also available for other Pandas objects, such as columns:

Alternatively, to convert the index or series to a list, use the tolist() method:

The above is the detailed content of How to Convert Pandas Series or Index to NumPy Array?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn