python-3.x


filtering dataframe column by beginning of string


I want to filter the following dataframe rows by the beginning 19 characters (meets requirements) of a string.
As of now the dataframe looks like this:
Name Reason
0 item1 {"state": "doesn't meet requirements" , "score": "0.6"}
1 item2 {"state": "meets requirements" , "score": "0.7"}
2 item3 {"state": "meets requirements" , "score": "0.8"}
3 item4 {"state": "doesn't requirements" , "score": "0.9"}
4 item5 {"state": "meets requirements" , "score": "0.7"}
5 item6 {"state": "doesn't requirements" , "score": "0.7"}
the result I am looking is for the dataframe to look like this:
Name Reason
0 item2 {"state": "meets requirements" , "score": "0.7"}
1 item3 {"state": "meets requirements" , "score": "0.8"}
2 item5 {"state": "meets requirements" , "score": "0.7"}
basically filtering so that the only rows left are the ones that begging with "meets requirements" in the "Reason" column
Thanks
#strip the spaces and compare with the prefix and then filter the rows
df[df.Reason.str.replace(' ','').str.startswith('{"state":"meetsrequirements"')]
Out[236]:
Name Reason
1 item2 {"state": "meets requirements" , "score": "0.7"}
2 item3 {"state": "meets requirements" , "score": "0.8"}
4 item5 {"state": "meets requirements" , "score": "0.7"}

Related Links

Why are exe files produced by bdist_wininst larger in python 3 than python 2?
Formatting issue when printing
Reuse variable name to point at different data
Registered URLs in a router not working
using shift() to compare row elements
PyQt load page - check error ErrorPageExtension
Why is being indent's wrong causes wrong function?
Can't install package because of Old Command in Setup.Py
Optimising HDF5 dataset for Read/Write speed
Unable to use print_control_identifiers() for my desktop application in pywinauto
else statement in “if in” function in python does not work
Python3 : “ ValueError: invalid literal for int() with base 10: '2.0' ”
Implement Gaussian Mixture Model using keras
How to slow down the speed of send_keys action in a selenium script using python?
Heroku app crashing while generating wtforms csrf token only when accessed from a custom domain on chrome
PEP8 warning when accessing protected member from classmethod

Categories

HOME
azure-ad-b2c
prestashop
desktop-bridge
sublimetext2
mapreduce
ibeacon
lock-free
semaphore
jython
php-curl
autoit
ng-bootstrap
asp.net-core-1.1
alias
ussd
citrus-framework
beagleboneblack
juju
upgrade
udf
ado
max-flow
graphframes
wildfly-swarm
coco2d-x
openmpi
zingchart
center
spss-modeler
write.table
msvcrt
pusher
keyboard-events
biginteger
zigbee
exif
appsflyer
react-starter-kit
triangulation
language-translation
documents4j
amortization
cocos2d-js
url-rewrite-module
javascript-framework
ransack
hybrid
squish
sitecore-pxm
office365-restapi
dgrid
ryu
tabular
public-key
pascalscript
windows-desktop-gadgets
dynamic-image-generation
txtextcontrol
lockbox-3
lightswitch-2012
micrium
dyld
intellitrace
kartograph
autokey
reactive-cocoa-4
journal
adam
html5-input-date
remotewebdriver
phonegap-pushplugin
nolearn
dynamic-arrays
ios-universal-app
d3dx
milliseconds
genson
page-title
validationrules
ichat
chain-of-responsibility
datapicker
html2latex
relevance
jrubyonrails
unobtrusive-javascript
lwuit-resource-editor
cedet
stringwriter
cmsamplebufferref
cryptostream
wap
nhibernate-queryover
response.write
proof-system
ergonomics

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App