A
A
Alisa Unylova2019-06-03 11:49:22
Python
Alisa Unylova, 2019-06-03 11:49:22

Finding values ​​in Pandas?

There is a column with values ​​of the form:

Zbx_login
Zbx_login1
Zbx_login2
Elg_login1
Elg_login3
Elg_login2

It is necessary to put records with the Elg prefix into a separate dataframe. What is the correct way to search in pandas?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman Voronov, 2019-06-03
@alisadvachee

There is a handy function - startswith , it will work well here.

import pandas as pd
df = pd.DataFrame(['Zbx_login', 'Zbx_login1', 'Zbx_login2', 'Elg_login1', 'Elg_login3', 'Elg_login2'], columns=['name'])
df_filtered = df[df.name.str.startswith('Elg_')]
df_filtered

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question