Filtrando com Strings
Filtrando o DF do Pandas com base em Strings
Mostrando o dataset que iremos manipular
python
out:
df3.head()
| ID_Pedido | Data_Pedido | ID_Cliente | Segmento | Pais | Regiao | ID_Produto | Categoria | Nome_Produto | Valor_Venda | Quantidade | |
|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | CA-2016-152156 | 2016-11-08 | CG-12520 | Consumer | United States | South | FUR-BO-10001798 | Furniture | Bush Somerset Collection Bookcase | 261.9600 | 3.0 |
| 1 | CA-2016-152156 | 2016-11-08 | CG-12520 | Consumer | United States | South | FUR-CH-10000454 | Furniture | Hon Deluxe Fabric Upholstered Stacking Chairs,... | 731.9400 | 3.0 |
| 2 | CA-2016-138688 | 2016-06-12 | DV-13045 | Corporate | United States | West | OFF-LA-10000240 | Office Supplies | Self-Adhesive Address Labels for Typewriters b... | 14.6200 | 2.0 |
| 3 | US-2015-108966 | 2015-10-11 | SO-20335 | Consumer | United States | South | FUR-TA-10000577 | Furniture | Bretford CR4500 Series Slim Rectangular Table | 957.5775 | 5.0 |
| 4 | US-2015-108966 | 2015-10-11 | SO-20335 | Consumer | United States | South | OFF-ST-10000760 | Office Supplies | Eldon Fold 'N Roll Cart System | 22.3680 | 2.0 |
buscando todas as strings, da coluna segmento, que começa com as letras 'Con'
python
out:
df3[ df3.Segmento.str.startswith('Con') ].head()
| ID_Pedido | Data_Pedido | ID_Cliente | Segmento | Pais | Regiao | ID_Produto | Categoria | Nome_Produto | Valor_Venda | Quantidade | |
|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | CA-2016-152156 | 2016-11-08 | CG-12520 | Consumer | United States | South | FUR-BO-10001798 | Furniture | Bush Somerset Collection Bookcase | 261.9600 | 3.0 |
| 1 | CA-2016-152156 | 2016-11-08 | CG-12520 | Consumer | United States | South | FUR-CH-10000454 | Furniture | Hon Deluxe Fabric Upholstered Stacking Chairs,... | 731.9400 | 3.0 |
| 3 | US-2015-108966 | 2015-10-11 | SO-20335 | Consumer | United States | South | FUR-TA-10000577 | Furniture | Bretford CR4500 Series Slim Rectangular Table | 957.5775 | 5.0 |
| 4 | US-2015-108966 | 2015-10-11 | SO-20335 | Consumer | United States | South | OFF-ST-10000760 | Office Supplies | Eldon Fold 'N Roll Cart System | 22.3680 | 2.0 |
| 5 | CA-2014-115812 | 2014-06-09 | BH-11710 | Consumer | United States | West | FUR-FU-10001487 | Furniture | Eldon Expressions Wood and Plastic Desk Access... | 48.8600 | 7.0 |
buscando todas as strings, da coluna segmento, que termina com as letras 'mer'
python
out:
df3[ df3.Segmento.str.endswith('mer') ].head()
| ID_Pedido | Data_Pedido | ID_Cliente | Segmento | Pais | Regiao | ID_Produto | Categoria | Nome_Produto | Valor_Venda | Quantidade | |
|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | CA-2016-152156 | 2016-11-08 | CG-12520 | Consumer | United States | South | FUR-BO-10001798 | Furniture | Bush Somerset Collection Bookcase | 261.9600 | 3.0 |
| 1 | CA-2016-152156 | 2016-11-08 | CG-12520 | Consumer | United States | South | FUR-CH-10000454 | Furniture | Hon Deluxe Fabric Upholstered Stacking Chairs,... | 731.9400 | 3.0 |
| 3 | US-2015-108966 | 2015-10-11 | SO-20335 | Consumer | United States | South | FUR-TA-10000577 | Furniture | Bretford CR4500 Series Slim Rectangular Table | 957.5775 | 5.0 |
| 4 | US-2015-108966 | 2015-10-11 | SO-20335 | Consumer | United States | South | OFF-ST-10000760 | Office Supplies | Eldon Fold 'N Roll Cart System | 22.3680 | 2.0 |
| 5 | CA-2014-115812 | 2014-06-09 | BH-11710 | Consumer | United States | West | FUR-FU-10001487 | Furniture | Eldon Expressions Wood and Plastic Desk Access... | 48.8600 | 7.0 |