python - Pandas - Filtering text and data -
we have learnt how filter through pandas in python thought try out on public data set. (http://data.wa.aemo.com.au/#stem-bids-and-offers)
i used august's data this.
the challenge set myself filter on $/mwh > 0 , had on bids. have learnt how use np.logical_and filter problem found can filter on either numerical or logical. not both.
i have approach works , gets me data , visualisation i'm after i'm there more efficient way of filtering text , numeric fields. problem approach works if character size different. i.e. if said bid or fib. pick both. only want pick bid. please point me in right direction?
here code:
#task: want filter out positive $/mwh bids #this requires 2 filters - 1 filter out $mwh > 0 , 1 filter bids # try converting numpy array , using filtering mechanisms there import numpy np df = pd.read_csv('stem-bids-and-offers-2017-08.csv') df.head(5) #i don't know how filter 'text' yet have use way using len function #this reduce bid/offer field characters df['bolength'] = df['bid or offer'].apply(len) df.head(5) filtbypricebid = np.logical_and(df['price ($/mwh)'] > 0, df['bolength'] == 3) filtbypricebid.head(5) df2 = df[filtbypricebid] df2.head(10) sns.kdeplot(df2['price ($/mwh)'], shade=true)
ps: attached kde plot came out of this. if wants provide interpretation on well, please feel free so! expecting normalised distribution unfortunately, not case.
i hope looking for.
you use &
have multiple filters together
sns.kdeplot(df[(df['price ($/mwh)'] > 0) & (df['bid or offer']=='bid')]['price ($/mwh)'], shade=true)
Comments
Post a Comment