-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathsquare-brackets-(2).py
More file actions
27 lines (22 loc) · 879 Bytes
/
square-brackets-(2).py
File metadata and controls
27 lines (22 loc) · 879 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
'''
Square Brackets (2)
100xp
Square brackets can do more than just selecting columns. You can also use them to get rows,
or observations, from a DataFrame. The following call selects the first five rows from the
cars DataFrame:
cars[0:5]
The result is another DataFrame containing only the rows you specified.
Pay attention: You can only select rows using square brackets if you specify a slice,
like 0:4. Also, you're using the integer indexes of the rows here, not the row labels!
Instructions
-Select the first 3 observations from cars and print them out.
-Select the fourth, fifth and sixth observation, corresponding to row indexes 3, 4 and 5,
and print them out.
'''
# Import cars data
import pandas as pd
cars = pd.read_csv('cars.csv', index_col = 0)
# Print out first 3 observations
print(cars[0:3])
# Print out fourth, fifth and sixth observation
print(cars[3:6])