Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python Cut Example

Tags:

python

cut

I'm looking for a way in python to achieve similar functionality to the unix cut utility. I know I can make a system call and process my data that way but I'd like to make it a bit more "pythonic" and do it with python libraries.

Example text

abcde:12345

I'd like to delimit on : and keep the second field:

cut -d':' -f2

to produce:

12345

thoughts?

like image 208
user735304 Avatar asked May 03 '11 00:05

user735304


People also ask

What does cut () do in Python?

cut() method in Python. Pandas cut() function is used to separate the array elements into different bins . The cut function is mainly used to perform statistical analysis on scalar data.

How do you cut a column in Python?

To delete rows and columns from DataFrames, Pandas uses the “drop” function. To delete a column, or multiple columns, use the name of the column(s), and specify the “axis” as 1. Alternatively, as in the example below, the 'columns' parameter has been added in Pandas which cuts out the need for 'axis'.

How do you split data into bins in Python?

Use pd. cut() for binning data based on the range of possible values. Use pd. qcut() for binning data based on the actual distribution of values.


1 Answers

You can do:

string.split(":")[1]

where string is your text

like image 172
manojlds Avatar answered Oct 08 '22 16:10

manojlds