3
I have a Dataframe with more than 5 thousand lines and more than 20 columns.
I want to select only a few rows, second column match criteria with specific values
SELECT *
FROM dataframe
WHERE colume_name = lista_de_valores
that is to say
import pandas as pd
df=pd.read_csv('arquivo.csv', encoding = "utf-8-sig", sep=",")
print(df.columns)
## Index(['idx', 'prod', 'number', 'date', ..., 'stockN'], dtype='object')
What I need is to create a new df2
, with all lines on which 'stockN'
is equal to a value, keeping some columns
lista_de_valores = {'stockN':['169', ..., '1390', '1464', '157', '3833']} # mais de 20 valores
df2 = pd.DataFrame(lista_de_valores, columns= ['idx', 'date', 'stockN'])
But despite the 'stockN'
come correct, the Dataframe comes with nan
in the other selected columns. What I’m missing here?
Thanks in advance!
you can share the database?
– Lucas
This answers your question? Filter lines in pandas by a list
– Lucas