I want to read a .xlsx file, do some things with the data and convert it to a dict to save it in a .json file. To do that I use Python3 and pandas. This is the code: I add here the source of the .xlsx file (Spanish government). Select “Fichero con todas las provincias”. You have to delete the
Tag: python
Python request.get error on Wikipedia image URL
Requests.get() does not seem to be returning the expected bytes for Wikipedia image URLs, such as https://upload.wikimedia.org/wikipedia/commons/0/05/20100726_Kalamitsi_Beach_Ionian_Sea_Lefkada_island_Greece.jpg: Answer Most websites block requests that come in without a valid browser as a User-Agent. Wikimed…
How do I construct a self-referential/recursive SQLModel
I want to define a model that has a self-referential (or recursive) foreign key using SQLModel. (This relationship pattern is also sometimes referred to as an adjacency list.) The pure SQLAlchemy implementation is described here in their documentation. Let’s say I want to implement the basic tree struct…
Most efficient way to compare the values of list one with list two returning a subset of list one
I have two lists of lists I need to compare the final values of each list and returning the numerical bit of list a that is not contained in list b … producing a list of values like [1072,…] The following code works: I would rather have something like this if it is faster: But that is matching on …
PyQt5/Pyqtgraph Get Numpy Array for What is Currently on the Scene
I have a pg.GraphicsLayoutWidget with some images and some ROIs displayed . I would like to get obtain a numpy array for what is currently on the scene, just like the export command in the context menu of the viewbox . Let an arbitrary RGB image (i.e. a numpy array) image be given. For example , I am using ht…
Proccesing audio from twilio media stream using Python
I am streaming call audio to my local server using Twilio Streams. For reference I used the offical guide from the Twilio Team. Decoding the audio and saving it to a .wav file works, although when playing back the audio sounds somewhat distored (“slow-motion” with compression artificats). You can …
Plotly (Python) – Can plotly inherit categories order setted in pandas?
A simple question: Instead of expliciting categories every time in plotly express, like: Can plotly inherit categorical order already setted in pandas? like: So in the end will be just: Answer To my knowledge, the order of the categories is not automatically implemented for the x-axis. But you don’t hav…
How to search for name in dataframe
For example I want to find all the people that has “Abbott” in their name df.loc[name in df[“Name”]] I tried this and it didn’t work Answer You can use str.contains with the column you are interested in searching
Regexp_replace “,” with “.” every other commas in spark
I have a dataframe that instead of . it has , and separators of numbers are also comma, I need to replace only odd comma to dot. The dataframe is very big but as an example, I have this: I want this df: Answer You can split on all commas , and later you can use for-loop: with range(0, len(splitted_data),
How to make the frequency table based on the multiple columns in python?
I guess it could be a duplicated question, but I could not find the solution. I want to make a frequency table in python. And this is an expected result that is similar to the frequency table. I tried using crosstab, groupby, and pivot_table functions, but all of them failed to get the correct result. How can…