Issue
I want to load only users who their status are "Disabled"
in Status
column into Pandas data frame. My initial code is like this
import pandas as pd
df = pd.read_excel('Users.XLSX', sheet_name='WebUsers', usecols="A,B")
print(df)
Which is bringing all users no matter they are "Disabled" or "Active". How can I add a filter like WHERE 'Status' == 'Disabled'
and load only disabled users into frame?
Solution
You can't do that with Pandas, you have to filter after Pandas loads the file:
df = (pd.read_excel('Users.XLSX', sheet_name='WebUsers', usecols=['A', 'B', 'Status'])
.query("Status == 'disabled'").drop(columns='Status'))
Note: parquet
is a column-oriented data file format so you can filter your dataframe before.
Answered By - Corralien
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.