Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprenda Loading Data into Pandas | Data Cleaning
Introduction to Pandas with AI

bookLoading Data into Pandas

AI in Action

import pandas as pd

df = pd.read_csv("passengers.csv")
print(df.head())

Reading Data from Files

Datasets are typically too large to be typed in manually or stored directly in code. That's why they are kept in external files on your computer or in online storage. To work with them in pandas, you first need to load the data into memory.

Most commonly, you will work with CSV files - tables where values are separated by commas. These files can be read with the pd.read_csv() function:

import pandas as pd

df = pd.read_csv("passengers.csv")
print(df.head())

Pandas can read many different data sources. You can explore all available options in the official documentation.

Reading Remote Files

If you want, you can also load files directly from the web. Just pass the URL instead of a file path.

1234
import pandas as pd df = pd.read_csv("https://staging-content-media-cdn.codefinity.com/courses/64641555-cae4-4cd0-8d29-807aeb6bc0c4/datasets/passengers.csv") print(df.head())
copy

Adjusting Parameters

Even in simple formats like CSV, there is room for different settings. You may want to add or remove a header, replace a comma with another separator, or handle unusual encodings. All this can be configured when loading the file:

import pandas as pd

# Change separator into a semicolon
df1 = pd.read_csv("data.csv", sep=";")
# Specify encoding type
df2 = pd.read_csv("data.csv", encoding="latin1")
# Read file without headers
df3 = pd.read_csv("data.csv", header=None)
# Assign custom column names
df4 = pd.read_csv("data.csv", names=["Date", "Product", "Price"])

1. Which pandas function loads data from a CSV file?

2. How do you read a tab-separated file named data.tsv? (Tab character is \t)

question mark

Which pandas function loads data from a CSV file?

Select the correct answer

question mark

How do you read a tab-separated file named data.tsv? (Tab character is \t)

Select the correct answer

Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 2. Capítulo 1

Pergunte à IA

expand

Pergunte à IA

ChatGPT

Pergunte o que quiser ou experimente uma das perguntas sugeridas para iniciar nosso bate-papo

Awesome!

Completion rate improved to 10

bookLoading Data into Pandas

Deslize para mostrar o menu

AI in Action

import pandas as pd

df = pd.read_csv("passengers.csv")
print(df.head())

Reading Data from Files

Datasets are typically too large to be typed in manually or stored directly in code. That's why they are kept in external files on your computer or in online storage. To work with them in pandas, you first need to load the data into memory.

Most commonly, you will work with CSV files - tables where values are separated by commas. These files can be read with the pd.read_csv() function:

import pandas as pd

df = pd.read_csv("passengers.csv")
print(df.head())

Pandas can read many different data sources. You can explore all available options in the official documentation.

Reading Remote Files

If you want, you can also load files directly from the web. Just pass the URL instead of a file path.

1234
import pandas as pd df = pd.read_csv("https://staging-content-media-cdn.codefinity.com/courses/64641555-cae4-4cd0-8d29-807aeb6bc0c4/datasets/passengers.csv") print(df.head())
copy

Adjusting Parameters

Even in simple formats like CSV, there is room for different settings. You may want to add or remove a header, replace a comma with another separator, or handle unusual encodings. All this can be configured when loading the file:

import pandas as pd

# Change separator into a semicolon
df1 = pd.read_csv("data.csv", sep=";")
# Specify encoding type
df2 = pd.read_csv("data.csv", encoding="latin1")
# Read file without headers
df3 = pd.read_csv("data.csv", header=None)
# Assign custom column names
df4 = pd.read_csv("data.csv", names=["Date", "Product", "Price"])

1. Which pandas function loads data from a CSV file?

2. How do you read a tab-separated file named data.tsv? (Tab character is \t)

question mark

Which pandas function loads data from a CSV file?

Select the correct answer

question mark

How do you read a tab-separated file named data.tsv? (Tab character is \t)

Select the correct answer

Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 2. Capítulo 1
some-alt