Pandas Basic
Pandas Basic
DATAFRAMEPara iniciantes
2025
CONTEÚDO
Inspecting DataFrames:
Explore essential methods to examine DataFrames, including .shape,
.isnull().sum().
Modifying DataFrames:
Pandas - Documentation
DataFrame
A DataFrame is a two-dimensional data structure, similar to a table,
used in Pandas for storing and manipulating data. It consists of rows
and columns, allowing easy access and manipulation of data.
In relation to SQL tables, both are similar, but the DataFrame allows
faster and more dynamic operations within the Python environment,
while SQL tables are manipulated directly in databases.
4
Loading Data csv into a DataFrame
pd.read_csv()
df_car = pd.read_csv(‘.. /dado/df_car_raw’)
df_car.head()
5
Inspecting DataFrames
1. Shape
df_car.shape
2. Columns
df_car.columns
3. Info
df_car.info
The .info() method provides a summary of the DataFrame, including column names, non- 6
null counts, and data types.
Accessing Data
1. Accessing Columns
7
Analyzing Data
8
2. Descriptive Statistics
df_car.describe()
9
Modifying DataFrames
1. Adding New Columns
Let's create a new column called "descricao" by combining "marca", "modelo", and "ano"
df_car['ano'].astype(str) Converts the year to a string (to avoid an error when adding an
int and a str)
2. Dropping Columns
Remove unnecessary columns
If you want to view the DataFrame without the column but without permanently removing
it, use
df_car.drop(['descricao'], axis=1)
10
Let's remove the new column "descricao" from the DataFrame df_car
df_car.drop(['descricao'], axis=1, inplace=True)
11
Transforming Data
How it works:
str.replace() is used to replace a substring within strings in a DataFrame or Series
column. It accepts two main parameters:
1. The pattern (regex or string) to be replaced
2. The replacement string
12
2. Clean "km" column
13
3. Clean "preco" column
print(df_car[['preco']])
r'R\$'
Removes the "R$" symbol (we need to use \ to escape the $ symbol).
r'\.'
Removes the dots (used to separate thousands).
r'\s'
Removes the spaces.
astype(float)
Converts the values to float so that you can perform calculations.
r'/\d+'
This pattern (regex) matches the slash / followed by one or more digits (\d+).
What will be removed is the slash and the numbers after it.
‘‘
Replaces the matched pattern (slash and numbers) with an empty string, meaning we
remove the slash and the second year.
15
Conclusion
These techniques form the foundation of data analysis with Pandas. In the next lesson,
we’ll explore label-based indexing using .loc and positional indexing with .iloc to access
specific rows and columns.
16
ANEXOS
17
PYHTON - INSTALAÇÃO
PYHTON.ORG
18
CUSTOMIZE INSTALLATION
OPTIONAL FEATURES
ADVANCED OPTIONS
19
CLOSE
20
2.POWER SHELL
21
ANEXO II
Instalando VS CODE
VS CODE - Download
EXECUTE O INSTALADOR
22
23
24
4. POWER SHELL- ExecutionPolicy
Digite
Get-ExecutionPolicy
25
PS C:\Windows\system32> SET-ExecutionPolicy AllSigned -Force
26
5.AMBIENTE VIRTUAL
No VS Code:
Yes, we trust
27
View > Terminal
28
O ambiente virtual está ativo
deactivate
Read more:
Ambiente Virtual no VSCode com Python - Tutorial Completo
29
6.CONFIGURAÇÃO DO VS CODE
CTRL + S
30
Observe que o JSON de configurações também refletiu as alterações
31
6.1. ARQUIVOS PYTHON SÃO MÓDULOS PYTHON
No exemplo:
aula1.py
Python
32
O que essa extensão faz?
Executa o código
Seleciona ambiente virtual
Debug
33
Configurando Extensão Code Runner
34
Acrescente a seguinte linha de configuração
"code-runner.runInTerminal": true
35
Em Manage > Setting > Json
Digite:
"code-runner.executorMap"
36
Em Manage > Setting > JSON
Acrescente:
"code-runner.ignoreSelection": true
Em Extensions digite om
37
Novamente em Extensions > Material Icon Theme
38
Novamente Manage > Setting > JSON
Acrescente:
"python.defaultInterpreterPath": "python"
39
ANEXOS III
venv\Scripts\activate
5. Escolher Kernel
7. Pandas
import pandas as pd
40
1. Crie o ambiente virtual
No terminal
python -m venv venv
venv\Scripts\activate
41
Installe Jupyter no ambiente virtual
Abra um Notebook no VS Code
42
Um novo Notebook será criado
No terminal digite:
43
Quando terminar digite:
44
import pandas as pd
45
Jupyter no navegador
No terminal digite:
jupyter notebook
46
Pronto! Você já pode usar seu notebook no navegador
47
Referências