Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Вивчайте Viewing the Data | Section
Data Manipulation with pandas
Секція 1. Розділ 13
single

single

bookViewing the Data

Свайпніть щоб показати меню

To view the first few rows of a dataset, use the head() method. This method accepts an integer argument that specifies how many rows to display (by default, it shows the first 5 rows). Display the first 10 rows of the dataset:

df = pd.read_csv('file.csv')
# Extracting the first 10 rows
first_lines = df.head(10)

To see the last few rows of a DataFrame, use the tail() method. It works the same way as the head() method:

df = pd.read_csv('file.csv')
# Extracting the last 10 rows
last_lines = df.tail(10)

Another useful method for exploring DataFrames is sample(). This method fetches random records from a DataFrame. By default, it retrieves a single random record unless specified otherwise.

df = pd.read_csv('file.csv')
# Extracting 10 random rows
random_lines = df.sample(10)
Завдання

Swipe to start coding

You are given a DataFrame named wine_data.

  • Extract the first 10 rows from this DataFrame and store the result in the first_lines variable.
  • Retrieve the last 15 rows from this DataFrame and store the result in the last_lines variable.
  • Select a random sample of 12 rows from this DataFrame and store the result in the random_rows variable.

Рішення

Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 1. Розділ 13
single

single

Запитати АІ

expand

Запитати АІ

ChatGPT

Запитайте про що завгодно або спробуйте одне із запропонованих запитань, щоб почати наш чат

some-alt