Course Content

Pandas First Steps

## Pandas First Steps

# Viewing the Data

To view the first few rows of a dataset in Python, we can utilize the `head()`

method. This function accepts an integer as its argument, which specifies the number of rows to display (by default, it shows first 5 rows). Let's take a look at the first 10 rows of our dataset:

If we want to see the last few rows of a dataframe, we can use the `tail()`

method. It works similarly to the `head()`

method:

Another useful function for exploring dataframes is `sample()`

. This function fetches random records from a dataframe. By default, it retrieves a single random record unless specified otherwise.

Task

We have a dataframe named `frame`

.

- We need to extract the first 10 rows from this dataframe.
- We need to retrieve the last 15 rows from this dataframe.
- We want to select a random sample of 12 rows from this dataframe.

Task

We have a dataframe named `frame`

.

- We need to extract the first 10 rows from this dataframe.
- We need to retrieve the last 15 rows from this dataframe.
- We want to select a random sample of 12 rows from this dataframe.

Everything was clear?

# Viewing the Data

To view the first few rows of a dataset in Python, we can utilize the `head()`

method. This function accepts an integer as its argument, which specifies the number of rows to display (by default, it shows first 5 rows). Let's take a look at the first 10 rows of our dataset:

If we want to see the last few rows of a dataframe, we can use the `tail()`

method. It works similarly to the `head()`

method:

Another useful function for exploring dataframes is `sample()`

. This function fetches random records from a dataframe. By default, it retrieves a single random record unless specified otherwise.

Task

We have a dataframe named `frame`

.

- We need to extract the first 10 rows from this dataframe.
- We need to retrieve the last 15 rows from this dataframe.
- We want to select a random sample of 12 rows from this dataframe.

Task

We have a dataframe named `frame`

.

- We need to extract the first 10 rows from this dataframe.
- We need to retrieve the last 15 rows from this dataframe.
- We want to select a random sample of 12 rows from this dataframe.

Everything was clear?

# Viewing the Data

To view the first few rows of a dataset in Python, we can utilize the `head()`

method. This function accepts an integer as its argument, which specifies the number of rows to display (by default, it shows first 5 rows). Let's take a look at the first 10 rows of our dataset:

If we want to see the last few rows of a dataframe, we can use the `tail()`

method. It works similarly to the `head()`

method:

Another useful function for exploring dataframes is `sample()`

. This function fetches random records from a dataframe. By default, it retrieves a single random record unless specified otherwise.

Task

We have a dataframe named `frame`

.

- We need to extract the first 10 rows from this dataframe.
- We need to retrieve the last 15 rows from this dataframe.
- We want to select a random sample of 12 rows from this dataframe.

Task

We have a dataframe named `frame`

.

- We need to extract the first 10 rows from this dataframe.
- We need to retrieve the last 15 rows from this dataframe.
- We want to select a random sample of 12 rows from this dataframe.

Everything was clear?

`head()`

method. This function accepts an integer as its argument, which specifies the number of rows to display (by default, it shows first 5 rows). Let's take a look at the first 10 rows of our dataset:

`tail()`

method. It works similarly to the `head()`

method:

`sample()`

. This function fetches random records from a dataframe. By default, it retrieves a single random record unless specified otherwise.

Task

We have a dataframe named `frame`

.

- We need to extract the first 10 rows from this dataframe.
- We need to retrieve the last 15 rows from this dataframe.
- We want to select a random sample of 12 rows from this dataframe.