I am trying to write a code that splits lists in a class of lists in two when a certain value is a middle element of the list and then produce two lists where the middle element becomes the end element in the first list and the first element in the second one. There can be more than n middle
Delete rows that do not contain specific text
I have a tabular file that looks like this: I’m trying to create a script to go through and delete the entire row if column 2 (‘KEGG_KOs’) does not begin with ‘K0’. I’m trying to create an output of: Previous responses have referred people to pandas DataFrame but I’ve…
Retrieve value from list from google datastore python
I have a list in python which is product of a query to Google’s Datastore, the list looks like this: I need to extract the ID of the entity which is 1111. I’ve tried the following with no success thus far: Any idea how I might be able to retrieve the ID value? Answer https://googlecloudplatform.gi…
How to get all external links found on a page using BeautifulSoup?
I’m reading the book, Web Scraping with Python which has the following function to retrieve external links found on a page: The problem is that it does not work the way it should. When i run it using the URL: http://www.oreilly.com, it returns this: Output: Question: Why are the first 16-17 entries cons…
Calculate yearly anomalies for several years on netcdf files in python
I need to calculate monthly, seasonal and annualy anomalies of air temperature of netcdf monthly files of 44 years with some function that allows me to obtain anomalies in the period on a monthly, seasonal and annualy automatically and save the results in a folder. I only know how to do It for one year and no…
Networkx: Creating a complete graph for a given set of nodes
I have a list as c4_leaves = [56,78,90,112]. I’m trying to create a complete graph using these elements in c4_leaves as nodes. Here’s what I’ve tried: And then the minimum spanning tree of the above graph as: When I draw G_ex, it gives me the correct graph, but when I print details of the mi…
Web scraping the data from multiple TOC using python or R
I am new to web scraping. I would like to collect the data from: https://www.sec.gov/Archives/edgar/data/814453/000119312518067603/d494599d10k.htm#tx494599_11 I can see a lot of TOCs are there. I would like to scrape the “Income before income taxes” word with the amount. Please share idea and thro…
How to use a lambda as parameter in python argparse?
I have something like this, the idea is that -f parameter to be a lambda. But i do not know how to do it when I called from a bash shell because if a try: I get error: “error: argument -f: invalid function value: ‘x : x-4′” Some help? Answer To be able to access imported functions/modu…
Paho MQTT Python Client: No exceptions thrown, just stops
I try to setup a mqtt client in python3. This is not the first time im doing this, however i came across a rather odd behaviour. When trying to call a function, which contains a bug, from one of the callback functions (on_connect or on_message), python does not throw an exception (at least it is not printed),…
How to plot normalized histogram with pdf properly using matplotlib?
I try to plot normalized histogram using example from numpy.random.normal documentation. For this purpose I generate normally distributed random sample. Then I fitt normal distribution to the data and calculate pdf. Display fitted pdf and data histogram. I use density=True, but it is obviously, that pdf and h…