Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

Split the string using the separator

# Split the string using the separator

text= "Orange,Apple,Grapes,WaterMelon,Kiwi"
print(text.split(','))
Comment

split strings around given separator/delimiter

# split strings around given separator/delimiter
# import Pandas as pd 
import pandas as pd 
   
# create a new data frame 
df = pd.DataFrame({'Location': ['Cupertino,California', 'Los Angles, California', 'Palo Alto, California']
                   }) 
   
df[['City','State']] = df.Location.str.split(',',expand=True) 
df
print(df)
Comment

split string into words and separators

def split_words_separators(an_input: str) -> list:
    """Returns two lists, one with words, and one with the separators used in input string"""
    merged = re.split(r"([ ,]+)", an_input)
    # the [::2] is to get the even indexes, which are the words
    # the [1::2] is to get the odd indexes, which are the separators
    return [merged[::2], merged[1::2]]
Comment

PREVIOUS NEXT
Code Example
Python :: error handling in python 
Python :: proper pagination django template 
Python :: python server 
Python :: pytorch convert tensor dtype 
Python :: group by dataframe 
Python :: how to join an array of characters in python 
Python :: python save picture in folder 
Python :: python googledriver download 
Python :: python draw tree 
Python :: python console install package 
Python :: python gui kivvy 
Python :: python easter egg 
Python :: python or 
Python :: firebase functions python 
Python :: boolien in python 
Python :: nltk hide download messages 
Python :: Python Print Variable Using the string formatting with positional arguments {} 
Python :: how to do merge sort in python 
Python :: opkg install python-lxml_2.2.8-r1_mips32el.ipk 
Python :: add prefix to names in directory python 
Python :: os.path.dirname(__file__) 
Python :: How to Loop Through Sets in python 
Python :: pairwise combinations groupby 
Python :: how to use ActionChains selenium python with WebDriverWait 
Python :: python remove vowels from string 
Python :: Python Difference between two timedelta objects 
Python :: select inverse with conditions pandas 
Python :: flask or django 
Python :: pandas recognize type from strings 
Python :: iterative binary search 
ADD CONTENT
Topic
Content
Source link
Name
5+9 =