extract

How to extract data from file and assign each data to each variables on python?

How to extract data from file and assign each data to each variables on python? Question: So i wannna know the solution from my question. I already tried this import re username = "" password = "" full_name = "" birth_date = "" phone_number = "" address = "" with open("file2.txt", "r") as f: contents …

Total answers: 2

list[I] becomes a list instead of an item

list[I] becomes a list instead of an item Question: I am a high school student doing a simple merge sort algorithm, but I encountered below error message. Help is much appreciated! File "main.py", line 22, in mergesort if l_list[i] <= r_list[j]: TypeError: ‘<=’ not supported between instances of ‘int’ and ‘list’ Here’s my code: list …

Total answers: 2

Regex exact match

Regex exact match Question: I have the following sentence: "The size of the lunch box is around 1.5l or 1500ml" How can I change this to: "The size of the lunch box is around 1.5 liter or 1500 milliliter" In some cases, the value might also be present as "1.5 l or 1500 ml" with …

Total answers: 2

str.extract within a function

str.extract within a function Question: I want to create a function and extract with str.extract the following string from my dataframe: 100 milliliter But I am unable to create the function. It does work without the function. I tried: def extract(str): pattern = str.extract(‘d+ milliliter, str) return (str) How can I solve this issue? Asked …

Total answers: 1

panda extract() operator return NaN

panda extract() operator return NaN Question: I need to extract specific values from data in a column on panda data frame and group another columns base on extracted values. the pattern that I need is U1 ,U2 ,U3 ,… U9. first of all I found the values on data with match: filtered = df[df[‘column1′].str.match(r'(Us*d)’) == …

Total answers: 1

Python Compressed file ended before the end-of-stream marker was reached. But file is not Corrupted

Python Compressed file ended before the end-of-stream marker was reached. But file is not Corrupted Question: i made a simple request code that downloads a file from a Server r = requests.get("https:…/index_en.txt.lzma") index_en= open(‘C:…index_en.txt.lzma’,’wb’) index_en.write(r.content) index_en.close when i now extract the file manually in the directorry with 7zip everything is fine and the file decrippts …

Total answers: 1

How to match a word surrounded by a prefix and suffix?

How to match a word surrounded by a prefix and suffix? Question: Is there any regex to extract words from text that are surrounded by a certain prefix and suffix? Example: test[az5]test[az6]test I need to extract the numbers surrounded by the prefix [az and the suffix ]. I’m a bit advanced in Python, but not …

Total answers: 2

Python regex to get the closest match without duplicated content

Python regex to get the closest match without duplicated content Question: What I need I have a list of img src link. Here is an example: https://studiocake.kiev.ua/wp-content/webpc-passthru.php?src=https://studiocake.kiev.ua/wp-content/uploads/photo_2020-12-27_12-18-00-2-333×444.jpg&nocache=1 https://studiocake.kiev.ua/wp-content/webpc-passthru.php?src=https://studiocake.kiev.ua/wp-content/uploads/IMG_4945-333×444.jpeg&nocache=1 https://studiocake.kiev.ua/wp-content/webpc-passthru.php?src=https://studiocake.kiev.ua/wp-content/uploads/tri-shokolada.png&nocache=1 I need get the following result: studiocake.kiev.ua/wp-content/uploads/photo_2020-12-27_12-18-00-2-333×444.jpg studiocake.kiev.ua/wp-content/uploads/IMG_4945-333×444.jpeg studiocake.kiev.ua/wp-content/uploads/tri-shokolada.png Problem I use the following regex: studiocake.kiev.ua.*(jpeg|png|jpg) But it doesn’t work the way I need. Instead of …

Total answers: 3

Python list with type strings

Python list with type strings Question: I have got a python list Year= [‘1997JAN’, ‘1997FEB’, ‘1997MAR’‘1997APR’………………………’2021SEP’’2021OCT’] I would like to extract only years from the above list but not the months How can I extract only years? Year = [1997,1997,1997,…………………2021,2021] Asked By: swin cine || Source Answers: If you have these dates: dates = [‘1997JAN’, …

Total answers: 3

Overwrite existing column and extract values to new columns based on different conditions

Overwrite existing column and extract values to new columns based on different conditions Question: i have this series which contains country,state,city and i would like to extract them accordingly- refer to the output table Region US* Arizona** Phoenix Mesa California** Los Angeles San Diego Sacramento Florida** Tampa Miami Canada* Central Canada** Montreal London my desired …

Total answers: 1