[Solved] select specific para from text file

You can try below pattern which is working: import re str1 = “StartString fcchwd dheoidfjewofd edeodei eddeed dd djded dojef efjefj fefije efoef; StartString wdjkndd dwojdpjf wodjojd wdjwjdm wodjow wdjwdjm ojdowj ww wdeswjd wdojwod; #jfejf /** hfhih **/ dijhfs wdjw StartString wkpwkd dokowdk djd owjidwo;” regex = re.compile(r'(StartString.+?;)’) l = regex.findall(str1) print(l) Output: C:\Users\Desktop>py x.py … Read more

[Solved] Getting the Python PMW module? [closed]

Pmw is a toolkit for building high-level compound widgets in Python using the Tkinter module. It’s not a standard library, you need to get it from the project homepage. 2 solved Getting the Python PMW module? [closed]

[Solved] Extract text with conditions in Python

Try with this: \d+\s*((?:Apple|Banana|Orange|Pineapple)s?\b[\s\S]*?)(?=$|\d+\s*(?:Apple|Banana|Orange|Pineapple)s?\b) See: Regex demo The code: import re regex = r”\d+\s*((?:Apple|Banana|Orange|Pineapple)s?\b[\s\S]*?)(?=$|\d+\s*(?:Apple|Banana|Orange|Pineapple)s?\b)” test_str = “I have 2 apples in my bag and apples are great food toeat. you shud eat apples daily. it is very good for health. 3 bananas are also good. it reduces fat.” matches = re.findall(regex, test_str, re.MULTILINE | re.IGNORECASE) … Read more

[Solved] How ubuntu software center make “search” operation? [closed]

It is open-source and it might even use Python. To find out what package installs Software Center: $ apt-file find -F /usr/bin/software-center software-center: /usr/bin/software-center To download the source code: $ mkdir software-center $ cd software-center/ $ apt-get source software-center Look for the word ‘search’ in the source code. utils/search_query.py seems relevant. It looks like it … Read more

[Solved] Converting python code into a function [closed]

This is one way. def calculate_average(): n1 = int(input(‘Enter First Number’)) n2 = int(input(‘Enter Second Number’)) n3 = int(input(‘Enter Third Number’)) return int(n1 + n2 + n3)/3 average = calculate_average() print(”) print(‘The Average Is:’) print(average) solved Converting python code into a function [closed]

[Solved] Converting list into array in python – Machine Learning

It’s not a must, but it’s very convenient because of a huge amount of handy and very fast (vectorized) functions/methods, provided by Numpy/SciPy modules. Actually most of the machine-learning methods (at least in the sklearn module) will try to convert input arrays into Numpy arrays, in order to be able to use Numpy’s functions/methods. Consider … Read more

[Solved] For and If functions

By your requirement, you should iterate through all the values in L. try out this code P=3 I=2 L = [2,4,6,8,10] x=[] y=? for i in L: x.append((P * i * y)/I) for idx,i in enumerate(x): if x <= 305: print “this” + L[idx] + “will not work” else: print “this” + L[idx] + “will … Read more

[Solved] How to check with more RegEx for one address in python using re.findall()

Finally I got answer from here How to combine multiple regex into single one in python? Working fine this import re re1 = r’\d+\.\d*[L][-]\d*\s[A-Z]*[/]\d*’ re2 = ‘\d*[/]\d*[A-Z]*\d*\s[A-Z]*\d*[A-Z]*’ re3 = ‘[A-Z]*\d+[/]\d+[A-Z]\d+’ re4 = ‘\d+[/]\d+[A-Z]*\d+\s\d+[A-z]\s[A-Z]*’ sentences = [string1, string2, string3, string4] generic_re = re.compile(“(%s|%s|%s|%s)” % (re1, re2, re3, re4)).findall(sentence) solved How to check with more RegEx for … Read more

[Solved] How to find and calculate the number of duplicated rows between two different dataframe? [closed]

You can sorted both DataFrames – columns c_x and c_y, for movies is used DataFrame.pivot, count non missing values by DataFrame.count and append to df1: df2[[‘c_x’,’c_y’]] = np.sort(df2[[‘c_x’,’c_y’]], axis=1) df2[‘g’] = df2.groupby([‘c_x’,’c_y’]).cumcount().add(1) df2 = df2.pivot(index=[‘c_x’,’c_y’], columns=”g”, values=”movie”).add_prefix(‘movie’) df2[‘number’] = df2.count(axis=1) print (df2) g movie1 movie2 number c_x c_y bob dan c f 2 uni a … Read more

[Solved] Convert first 2 letters of all records to Uppercase in python

You may use map and Convert you data as you required: try below: import pandas as pd df = pd.DataFrame({‘name’:[‘geeks’, ‘gor’, ‘geeks’, ‘is’,’portal’, ‘for’,’geeks’]}) df[‘name’]=df[‘name’].map(lambda x: x[:2].upper()+x[2:]) print (df) output: name 0 GEeks 1 GOr 2 GEeks 3 IS 4 POrtal 5 FOr 6 GEeks demo 1 solved Convert first 2 letters of all records … Read more