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

How to create a frame/ rectangle around an image by user input?
How can I download zip files with aiohttp and asyncio?
Remove characters from string using replace()
columnspan in grid options dose't function
Reformat csv file using python?
character issue in python with non ascii characters
Pandas to MatPlotLib with Dollar Signs
How to use Global Variable in Python
python numba fingerprint error
web scraping in python using multiple identities
Why does urllib.parse.urlencode not change '_' into %5F?
Providing a custom command class to setup.py in a separately installed package
count distinct occurrences in pandas
prlimit and ulimit -u does not seem to work
Python Print Displays
iPython widgets: interact() with html result

Categories

HOME
javascript
visual-c++
struts-1
mercurial
vuejs2
spring-integration
parallel-processing
crontab
version-control
bundle
node-modules
php-curl
hashbang
azure-keyvault
twain
smartsheet-api
sticky
react-native-ios
dashboard
powerapps
adf
gitbook
lightbox
raid
symfony-2.7
ponyorm
labels
coco2d-x
capybara
query-optimization
videogular
harmon.ie
vsts-api
keypress
angularjs-ng-pluralize
staruml
dockerhub
jsignature
pixi.js
finch
mobile-website
ifconfig
targit
wrap
tidytext
musicxml
content-type
findstr
wifi-direct
spring-hateoas
shiny-server
information-gain
kanban
mongify
failovercluster
antlrworks
amortization
feedparser
icmp
wincvs
acrcloud
idx
winrar
cakephp-bake
theano-cuda
paint-code
openshift-client-tools
google-directory-api
azure-traffic-manager
socketchannel
google-reporting-api
railway.js
label-for
flask-migrate
locomotivecms
lucidworks
rsyntaxtextarea
angularjs-ng-change
yahoo-squidb
outer-join
pop-up
elementtree
html-heading
unreal-development-kit
leksah
learn-ruby-on-rails
django-i18n
msxml3
mybb
seekbarpreference
self-interpreter
user-feedback
fastcgi++
httperf
jquery-svg
wadl
async-ctp
setupapi
control-characters
lexical
content-management
weak-references
bde
morphological-analysis

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App