Find how many numbers two numbers have in common

So I’m trying to make a program that tells the user how many numbers both inputted numbers have in common FOR EXAMPLE: if inputted n1 = 765 and n2 = 572 then the program returns 2 because both numbers …

3D numpy array threshold comparison

I’m trying to solve whether or not each element in a 3d numpy array fits within a certain threshold. Currently I have nested for loops that get the job done, but it’s really slow and I don’t have all …

Python best practices — can I set an object attribute to call a class method?

I am building a tool to query all DNS records for a hostname. Each hostname will create a ScanObject object, which will call another module to do the queries upon instantiation. I create class methods …

Factor out the name of the dataframe in python pandas to get better to read mathematical expressions

If you do for example mathematical operations with columns of a python pandas dataframe (call it data), you repeatedly have to write data do access the columns, which is very annoying, if you want …

How to split a complex sentence string, keeping the delimiter, but not also placing the demiiter where it shouldn’t be

I came across this snippet on Grepper: line = “” d = “>” s = [e+d for e in line.split(d) if e] print(s) #Output: #[““, “<...

Add a character at start of a regex match in Pandas

I have a dataframe that has two columns, id and text df = pd.DataFrame([[1, ‘Hello world 28’], [2, ‘Hi how are you 9′], [3, ’19 Hello’]], columns=[‘id’,’text’]) id text 1 Hello world 28 …

Sort dataframe by substring condition excluding similar strings

I have a dataframe with a string type column named ‘tag’, tag has three categories (data_types): df[‘tag’] data_types=[‘DATA’,’DATAKIND’,’DATAKINDSIM’] If I want to count the number of rows there are …

Test of one dataframe in another

I have a pyspark dataframe df: A B C E00 FT AS E01 FG AD E02 FF AB E03 FH AW E04 FF AQ E05 FV AR E06 FD AE and another smaller pyspark dataframe but with 3 rows with …

Downloading all JS files using Scrapy?

I am trying to crawl a website searching for all JS files to download them. I am new to Scrapy and I have found that I can use CrawlSpider but seems I have an issue with LinkExtractors as my parser is …

CSV data to Python dictionary

I wrote my data which was in lists and dicts to a csv file, and when i import the csv file using pd.read_csv(‘file.csv’), everything becomes strings. How can i keep or convert it to its original …