Filter numbers (that start with 1) - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Data Science (https://python-forum.io/forum-44.html) +--- Thread: Filter numbers (that start with 1) (/thread-28666.html) |
Filter numbers (that start with 1) - zinho - Jul-28-2020 Hi how filter number in column CFOP that which start with number 1xxx I have a column CFOP with number type like this (Dtype int64) CFOP 5927 5403 5102 6152 6209 1102 2353 1353 1556 2923 2102 1411 1202 2152 1949 6202 But I need get number that start 1 import pandas as pd cols = ['CFOP', 'QUANTIDADE', 'VC', 'BC'] xl = pd.read_excel(r'C:\Users\alexandre.goncalves\Documents\Projetos_Python\Fat_3.xlsx', sheet_name='geral', usecols=cols) # How to filter data in column CFOP which start with number 1, I try this print(xl.loc[xl['CFOP'].isin([1102,1353,1556,1411,1202,1949])]) RE: Filter numbers (that start with 1) - scidam - Jul-28-2020 I would convert the column to the string type and use startswith , e.g. xl.loc[xl['CFOP'].astype(str).str.startswith('1')] RE: Filter numbers (that start with 1) - zinho - Jul-29-2020 Hi scidam Good ideia, thank you! |