Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lære Indexes and Values | Basics
Introduction to pandas [track]
course content

Kursusindhold

Introduction to pandas [track]

Introduction to pandas [track]

1. Basics
2. Reading and Exploring Data
3. Accessing DataFrame Values
4. Aggregate Functions

book
Indexes and Values

Series in pandas differ from numpy arrays in that they have indexes. These can be integers, floating-point numbers, strings, time series.

To get the series' indexes, use the .index attribute of a series object. To get values, use the values attribute. By default, indexes are integers starting from 0, but if you want to change them, you simply may reassign new list of indexes to the .index attribute. For instance,

12345678910111213
# Importing library import pandas as pd # Creating pandas series ser = pd.Series([1000, 2500, 1700]) # Getting series' indexes and values print(ser.index) print(ser.values) print(ser) # Changing series' indexes ser.index = ['first', 'second', 'third'] print(ser)
copy

As you can see, initial indexes were 0, 1, 2. After changing, they became 'first', 'second', 'third'.

Var alt klart?

Hvordan kan vi forbedre det?

Tak for dine kommentarer!

Sektion 1. Kapitel 3

Spørg AI

expand
ChatGPT

Spørg om hvad som helst eller prøv et af de foreslåede spørgsmål for at starte vores chat

course content

Kursusindhold

Introduction to pandas [track]

Introduction to pandas [track]

1. Basics
2. Reading and Exploring Data
3. Accessing DataFrame Values
4. Aggregate Functions

book
Indexes and Values

Series in pandas differ from numpy arrays in that they have indexes. These can be integers, floating-point numbers, strings, time series.

To get the series' indexes, use the .index attribute of a series object. To get values, use the values attribute. By default, indexes are integers starting from 0, but if you want to change them, you simply may reassign new list of indexes to the .index attribute. For instance,

12345678910111213
# Importing library import pandas as pd # Creating pandas series ser = pd.Series([1000, 2500, 1700]) # Getting series' indexes and values print(ser.index) print(ser.values) print(ser) # Changing series' indexes ser.index = ['first', 'second', 'third'] print(ser)
copy

As you can see, initial indexes were 0, 1, 2. After changing, they became 'first', 'second', 'third'.

Var alt klart?

Hvordan kan vi forbedre det?

Tak for dine kommentarer!

Sektion 1. Kapitel 3
Vi beklager, at noget gik galt. Hvad skete der?
some-alt