strip

Strip A specific part from a url string in python

Strip A specific part from a url string in python Question: Im passing through some urls and I’d like to strip a part of it which dynamically changes so I don’t know it firsthand. An example url is: https://…?pid=2&gid=lostchapter&lang=en_GB&practice=1&channel=desktop&demo=2 And I’d like to strip the gid=lostchapter part without any of the rest. How do I …

Total answers: 5

Concatenate text file lines with condition in python

Concatenate text file lines with condition in python Question: I have a text file in this format: 0.jpg 12,13,14,15,16 0.jpg 13,14,15,16,17 1.jpg 1,2,3,4,5 1.jpg 2,3,4,5,6 I want to check if the image name is the same and then concatenate those lines into one line with the following format: 0.jpg 12,13,14,15,16 13,14,15,16,17 1.jpg 1,2,3,4,5 2,3,4,5,6 I …

Total answers: 1

Remove text lines and strip lines with condition in python

Remove text lines and strip lines with condition in python Question: I have a text file in this format: 000000.png 712,143,810,307,0 000001.png 599,156,629,189,3 387,181,423,203,1 676,163,688,193,5 000002.png 657,190,700,223,1 000003.png 614,181,727,284,1 000004.png 280,185,344,215,1 365,184,406,205,1 I want to remove the lines that don’t have a [number1,number2,number3,number4,1] or [number1,number2,number3,number4,5] ending and also strip the text line and remove the …

Total answers: 1

Extracting only a number and letter F from the column of a pandas dataframe

Extracting only a number and letter F from the column of a pandas dataframe Question: I have some data as below, AST_NAME 2F 3F 4F 5F 2-F-C 3-F-A 4-F-C 4-F-D 5-F-E 5-F-F SwB 6-F-G SwB 7-F-A I want to extract the number and letter F only from those values like 2-F-C or 3-F-D. My desired …

Total answers: 2

How to remove text from a string after a specific character?

How to remove text from a string after a specific character? Question: My program is like the command prompt (cmd) but much simpler. I am creating a command called, ‘bd’ which stands for back (one) directory. There is a path string: path = "C:/Program Files/node.js" and I want to remove the last directory ‘/node.js’ but …

Total answers: 2

How to Left Strip Only "one" Zero from string in Python

How to Left Strip Only "one" Zero from string in Python Question: I have a string of numbers in this format "IIDDDDDDDD" where "I" are the integers and "D" are the decimals and the string always contains 10 numbers. I need to format it as II.DDDDDDDD but some times after formatting the number is eg: …

Total answers: 1

How can I convert text to columns with Python?

How can I convert text to columns with Python? Question: I have this data: Event|Time|Meta|Meet|Date 50 Y Free|22.30|U|IL NASA Winter Blast Off|Nov 30, 2018 100 Y Free|55.50|U|Greg’s Super Splash|Jun 16, 2011 50 Y Breast|27.07|X|CCIW Swimming Championships|Feb 10, 2006 50 L Breast|33.70||1st Cyprus International Masters Swim Meet|Oct 22, 2016 100 Y Breast|58.97||CCIW Swimming Championships|Feb 10, 2006 …

Total answers: 1

How to convert the string to date time format?

How to convert the string to date time format? Question: I have the following string 20211208_104755, representing date_time format. I want to convert it to the python datetime format using datetime.strip() method. mydatetime = "20211208_104755" datetime_object = datetime.strptime(mydatetime, ‘%y/%m/%d’) However I am getting the following error. ValueError: time data ‘20211208’ does not match format ‘%y/%m/%d’ …

Total answers: 2

Removing whitespace from each value in a list

Removing whitespace from each value in a list Question: I want to write a function where I remove whitespace from the front and back of each string in a list. This is my list called t: [‘Specialty Food’, ‘ Restaurants’, ‘ Dim Sum’, ‘ Imported Food’, ‘ Food’, ‘ Chinese’, ‘ Ethnic Food’, ‘ Seafood’] …

Total answers: 4

How to strip/remove certain characters from a lsit

How to strip/remove certain characters from a list Question: I am currently trying to remove certain characters recursively from a python list. I have a list: lst1 = [‘ZINC1_out.pdbqt’, ‘ZINC2_out.pdbqt’, ‘ZINC3_out.pdbqt’] I would like to remove the ‘_out’ so that the list looks like this >>lst1 [‘ZINC1.pdbqt’, ‘ZINC2.pdbqt’, ‘ZINC3.pdbqt’] My current code looks like this: …

Total answers: 3