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 :: pd.to_excel header char vertical 
Python :: pandas dataframe how to store 
Python :: python deconstruct tuple 
Python :: how delet an obj from memori in python 
Python :: change xlabel size 
Python :: two lists with identical entries get order 
Python :: to create an array with values that are spaced linearly in a specified interval 
Python :: how to make pictures whit python 
Python :: looping emails using a database with python code 
Python :: Examples pandas.read_hfd5() 
Python :: Flatten List in Python Using NumPy Ravel 
Python :: Math Module asin() Function in python 
Python :: remap values in a column based on condition from another dataframe 
Python :: stop level of the broker 
Python :: prolog split list positive negative 
Python :: empty python 
Python :: dict keys in tcl 
Python :: python ordereddict initialization 
Python :: Broadcasting with NumPy Arrays Plotting a two-dimensional function Example 
Python :: python antigravity 
Python :: Python3: Deleting even and only showing uneven numbers from, set list. 
Python :: Python NumPy hstack Function Example with 2d array 
Python :: How can Clone or Duplicate a Row Using np.tile 
Python :: Python __ne__ 
Python :: function nbYear(p0, percent, aug, p) { let n = 0; while(p0 < p) { p0 = p0 + Math.round(p0 * (percent/100)) + aug; n ++; } return n; } 
Python :: NumPy right_shift Syntax 
Python :: change admin password djano 
Python :: penggunaan values di python 
Python :: python dependency injection 
Python :: python extract multiple values from a single cell in a dataframe column using pandas 
ADD CONTENT
Topic
Content
Source link
Name
7+1 =