I am really new in Python. I get a little confused with when I tried to filter values above a threshold.
For example:
A B C D E F G
1 x x x x x 1000
3 x x x x x 100000
4 x x x x x 10
1 x x x x x 100
4 x x x x x 1000
5 x x x x x 1000000
Assuming I would wanna filter Column G, for all values of 1000 and above, how do i continue from my current code ? I have already filtered the specific text and date from other columns, but i am unsure on how to filter values above a threshold.
import pandas as pd
import numpy as np
import openpyxl
from numpy.random import choice
df = pd.read_excel('filepath', sheet_name = 'Sheet1')
df_sample = df.loc[df['Bill Description'].str.contains("Invoice") & df_my['Bill Date'].ge('15/12/2019')]
#to filter values 1000 and above
Appreciate if you can show me the code, i have tried a few but they dont work out.
Thanks !
CodePudding user response:
Try this:
df[df['G'] >= 1000]
CodePudding user response:
Or just :
df_sample = df.loc[df['Bill Description'].str.contains("Invoice") & df_my['Bill Date'].ge('15/12/2019') & df['G'].ge(1000)]
CodePudding user response:
Continue your filter if you want to reduce again your dataframe
df_sample = df.loc[df['Bill Description'].str.contains("Invoice")
& df_my['Bill Date'].ge('15/12/2019')
& df[df['G'].ge(1000)]]