Movatterモバイル変換


[0]ホーム

URL:


Skip to main content
Ctrl+K

pandas.DataFrame.index#

DataFrame.index#

The index (row labels) of the DataFrame.

The index of a DataFrame is a series of labels that identify each row.The labels can be integers, strings, or any other hashable type. The indexis used for label-based access and alignment, and can be accessed ormodified using this attribute.

Returns:
pandas.Index

The index labels of the DataFrame.

See also

DataFrame.columns

The column labels of the DataFrame.

DataFrame.to_numpy

Convert the DataFrame to a NumPy array.

Examples

>>>df=pd.DataFrame({'Name':['Alice','Bob','Aritra'],...'Age':[25,30,35],...'Location':['Seattle','New York','Kona']},...index=([10,20,30]))>>>df.indexIndex([10, 20, 30], dtype='int64')

In this example, we create a DataFrame with 3 rows and 3 columns,including Name, Age, and Location information. We set the index labels tobe the integers 10, 20, and 30. We then access theindex attribute of theDataFrame, which returns anIndex object containing the index labels.

>>>df.index=[100,200,300]>>>df    Name  Age Location100  Alice   25  Seattle200    Bob   30 New York300  Aritra  35    Kona

In this example, we modify the index labels of the DataFrame by assigninga new list of labels to theindex attribute. The DataFrame is thenupdated with the new labels, and the output shows the modified DataFrame.


[8]ページ先頭

©2009-2025 Movatter.jp