Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lære Accessing using .loc[] [1/3] | Accessing DataFrame Values
Introduction to pandas [track]
course content

Kursinnhold

Introduction to pandas [track]

Introduction to pandas [track]

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

book
Accessing using .loc[] [1/3]

.loc[] is pandas property that allows to access a group of rows and columns by label(s) or a boolean array.

First, you can get rows by their indexes. Pass index/range of indexes between square brackets.

Note that right boundary is inculded while slicing within .loc[]

123456789
# Importing library import pandas as pd # Reading csv file df = pd.read_csv('https://codefinity-content-media.s3.eu-west-1.amazonaws.com/67798cef-5e7c-4fbc-af7d-ae96b4443c0a/audi.csv') # Get the first row (index - 0) print(df.loc[0]) # Get the 9th - 11th rows (indexes 8, 9, 10) print(df.loc[8:10])
copy

To get all rows, pass the colon : between square brackets.

Alt var klart?

Hvordan kan vi forbedre det?

Takk for tilbakemeldingene dine!

Seksjon 3. Kapittel 6

Spør AI

expand
ChatGPT

Spør om hva du vil, eller prøv ett av de foreslåtte spørsmålene for å starte chatten vår

course content

Kursinnhold

Introduction to pandas [track]

Introduction to pandas [track]

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

book
Accessing using .loc[] [1/3]

.loc[] is pandas property that allows to access a group of rows and columns by label(s) or a boolean array.

First, you can get rows by their indexes. Pass index/range of indexes between square brackets.

Note that right boundary is inculded while slicing within .loc[]

123456789
# Importing library import pandas as pd # Reading csv file df = pd.read_csv('https://codefinity-content-media.s3.eu-west-1.amazonaws.com/67798cef-5e7c-4fbc-af7d-ae96b4443c0a/audi.csv') # Get the first row (index - 0) print(df.loc[0]) # Get the 9th - 11th rows (indexes 8, 9, 10) print(df.loc[8:10])
copy

To get all rows, pass the colon : between square brackets.

Alt var klart?

Hvordan kan vi forbedre det?

Takk for tilbakemeldingene dine!

Seksjon 3. Kapittel 6
Vi beklager at noe gikk galt. Hva skjedde?
some-alt