Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Filter numbers (that start with 1)
#1
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])])
Quote
#2
I would convert the column to the string type and use startswith, e.g.

xl.loc[xl['CFOP'].astype(str).str.startswith('1')]
Quote
#3
Hi scidam

Good ideia, thank you!
Quote

Top Page

Forum Jump:


Users browsing this thread: 1 Guest(s)