@sidonduarte/

pandas-filtering-by-substring

Python

No description

fork
loading
Files
  • main.py
  • exemplo.txt

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.8044353063606846","path":"main.py","file":{"path":"main.py","content":{"asEncoding":{"base64":"IyMKIyBMZW5kbyBjc3YgZSBmaWx0cmFuZG8gcG9yIGNvbHVuYQojIFJlc3Bvc3RhIFNPcHQKIyBodHRwczovL3B0LnN0YWNrb3ZlcmZsb3cuY29tL3EvMzczNzEzLzc0MTIKIyBQb3IgU2lkb24gMjAxOQojIwoKaW1wb3J0IHBhbmRhcyBhcyBwZAoKIyBMZW5kbyBvIGNzdiAKdHh0ID0gImV4ZW1wbG8udHh0IgpkZiA9IHBkLnJlYWRfY3N2KHR4dCwgc2tpcHJvd3M9WzBdLCAgc2VwPSc7JywgaGVhZGVyPU5vbmUpCnByaW50KCcnLCdEYXRhZnJhbWUgb3JpZ2luYWw6JywgZGYsIHNlcD0nXG4nKQoKIyBGaWx0cmFuZG8KcyA9ICdDQ01YMTgnCmRmX2ZpbHRlcmVkID0gZGZbZGZbMV0uc3RyLmNvbnRhaW5zKHMpXQoKIyBBcHJlc2VudGFuZG8gbyByZXN1bHRhZG8KcHJpbnQoJycsJ0RhdGFmcmFtZSBmaWx0cmFkbzonLGRmX2ZpbHRlcmVkLHNlcD0nXG4nKQoKCg=="},"asBuffer":null},"loaded":true}}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
##
# Lendo csv e filtrando por coluna
# Resposta SOpt
# https://pt.stackoverflow.com/q/373713/7412
# Por Sidon 2019
##

import pandas as pd

# Lendo o csv 
txt = "exemplo.txt"
df = pd.read_csv(txt, skiprows=[0],  sep=';', header=None)
print('','Dataframe original:', df, sep='\n')

# Filtrando
s = 'CCMX18'
df_filtered = df[df[1].str.contains(s)]

# Apresentando o resultado
print('','Dataframe filtrado:',df_filtered,sep='\n')