Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 205301

grepl function in python

$
0
0

I want to recreate a snippet code from R to Python. I have this tibble from R (dataframe in Python) which is somehow look like this:

column1       column2                                 column3
amsterdam     het dag calamiteit bij doen gratis dag  2013
rotterdam     blijdorp groet gratis burp het ik ben   2015

with this code below, I tried to extract description as single character string. This is the code:

#R code
for (i in 1:nrow(tibble)) {
    des <- pull(tibble[i,2])
}

#Python code
for i in df:    
    des = df['column2'].str.split(expand=True).stack()

and then the series of des (we got from df['column']) would look like this in python:

het
dag
calamiteit
bij
doen
gratis
dag
blijdorp
groet
burp
het
ik
ben

But, then I want to recreate this code from R to Python which I don't know how:

if (grepl("^\\s*$", des) == TRUE) { # if description is only whitespace then skip
    trns <- tibble(translatedText = "", detectedSourceLanguage = "", text = "")

especially the grepl function.

What does it equal to in Python? and what's the best Python code to recreate that? thank you


Viewing all articles
Browse latest Browse all 205301

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>