I have a problem trying to run doctest from the Sphinx Tutorial. I have the directory tree below but I cannot run a doctest for lumache.py. How would be able to make it so that lumache.py is importable with the pathlib function in conf.py which is sys.path.insert(0, pathlib.Path(__file__).parents[2].resolve()…
Tag: python
Is there a way to have SQLAlchemy NOT change 1 to True and 0 to False for BIT columns?
I am using SQLAlchemy to read data from a SQL Server database and then turning the table data to a csv file to later hand off. However, I noticed when there is a 1 or 0 in a SQL Server table field, the csv output has True or False instead. I know to Python, it’s still a number since True
How to create pivot table from a pandas dataframe having string data types in the correct order
I have a dataframe which looks like below, Here is the same data in table format which you can copy/paste, Here is the same data in dictionary format which you can copy/paste, I tried using below code, but some of the SourceName was having wrong type, eg ‘peptide magainin’ should be a CHEMICAL, bu…
Comparing two text files and the matches go to a new file
In python I would like to find a way to compare two text files and read one line by line and find it’s match if any in the other file. If they match I would like to take that string and write it to a new file. I do not know how I would even start this the only thing
How to create tensorflow dataset from runtime generated images?
So, I start a small project based on tensorflow and could not understand how to prepare dataset generated from memory input. I have a random number of sources, that generate images. Than I pass it to python script. Images created as bytes array with png format. I collect images to array, and want to prepare d…
finding which person got highest percentage according to their marks
The first line of the input contains an integer which represents the number of lines The next n lines represent a space-separated list of the person and their marks in the four subjects output should be name of the highest percentage? for example input:- Output:- code :- Answer Is this something that you̵…
Get the index of the largest two values per row
For each row, I would like to get the index of the largest two values. Here’s the result I would like to obtain: Answer Use np.argsort along the second axis and take last two values reversed.
Replace multiple strings in place that match
I want to replace multiple strings in my list of dataframes that match. I cannot get these to match and replace in place, instead it produces additional row entries. Here’s the example data: I know that int_text is the same as extract_text, but in some instances I may only have one np.log for clean_text…
How can I optimze Django Code to only one query request
I have a simple django project which displays previous reservations dates based on id’s. However currently there are 2 requests being made. (N+1 sql requests, where N is the reservation’s count) Do you have any idea how i would be able to optimize this code to only 1 query? This is the model.py file Thi…
When I inherit from frozenset, I get TypeError: object.__init__() takes exactly one argument (the instance to initialize)
I want to inherit from frozenset and change the constructor. What I actually want to do is to make a singleton fronzeset, but instead here I’ll provide a simplified example: However, when I try to create an instance of B, I get an error: What’s going on and how to fix this? Answer For technical re…