Featured Post

14 Top Data Pipeline Key Terms Explained

Image
 Here are some key terms commonly used in data pipelines 1. Data Sources Definition: Points where data originates (e.g., databases, APIs, files, IoT devices). Examples: Relational databases (PostgreSQL, MySQL), APIs, cloud storage (S3), streaming data (Kafka), and on-premise systems. 2. Data Ingestion Definition: The process of importing or collecting raw data from various sources into a system for processing or storage. Methods: Batch ingestion, real-time/streaming ingestion. 3. Data Transformation Definition: Modifying, cleaning, or enriching data to make it usable for analysis or storage. Examples: Data cleaning (removing duplicates, fixing missing values). Data enrichment (joining with other data sources). ETL (Extract, Transform, Load). ELT (Extract, Load, Transform). 4. Data Storage Definition: Locations where data is stored after ingestion and transformation. Types: Data Lakes: Store raw, unstructured, or semi-structured data (e.g., S3, Azure Data Lake). Data Warehous...

The Easy Way to Split String Python Partition Method

Here's a way without the Split function you can split (or extract) a substring. In Python the method is Partition. You'll find here how to use this method with an example. 


Split string using the Partition

How to Split the string using Partition method

 

Returns Left side part

Example-1

my_string='ABCDEFGH||10||123456.25|'

my_partition=my_string.partition('|')[0]

print(my_partition)


Output

|10||123456.25|


** Process exited - Return Code: 0 **
Press Enter to exit terminal

Example-2

Returns from the separator to last of the string.

my_string='ABCDEFGH||10||123456.25|'
my_partition=my_string.partition('|')[-1]
print(my_partition)

Output

|10||123456.25|


** Process exited - Return Code: 0 **
Press Enter to exit terminal


The use of Rpartition to split a string in Python


Example-1

Returns except right side last separator.

my_string='ABCDEFGH||10||123456.25|'
my_partition=my_string.rpartition('|')[0]
print(my_partition)

Output

ABCDEFGH||10||123456.25


** Process exited - Return Code: 0 **
Press Enter to exit terminal

Example-2

Returns no string

my_string='ABCDEFGH||10||123456.25|'
my_partition=my_string.rpartition('|')[-1]
print(my_partition)


Output




** Process exited - Return Code: 0 **
Press Enter to exit terminal


Top Udemy courses

Comments

Popular posts from this blog

How to Fix datetime Import Error in Python Quickly

SQL Query: 3 Methods for Calculating Cumulative SUM

Big Data: Top Cloud Computing Interview Questions (1 of 4)