Hi I am looking to dedup my records ordered by cancel date so I will only be interested in the most recent record. sample data id cancel_date type_of_fruit 1 2021-03-02 apple 1 2021-01-01 apple 2 2021-02-01 orange expected output id cancel_date type_of_fruit 1 2021-03-02 apple 2 2021-02-01 orange I wrote the SQL way but I have to implement this logic
Tag: database
How to convert rows to columns in a Pandas groupby?
I have a table containing price data for a set of products over 6 months. Each product has a unique id (sku_id) and can be from size 6-12. We measured the price each day, and generated a table similar to the example below. Source indicates what website the price was on (can be 1-4). Now, I want to perform some
Django – OperationalError after deleting migration files
In the earliest days of my system, before i knew how to utilize django’s built-in User model, i had my own class named myUser which i intended to use for the same purpose. i ended up deleting this one and instead using django’s User model. all was fine for a while. then i tried to change the id of all
How to capture error messages via Python when inserting data in QuestDB?
Currently I am saving data to QuestDB through Python via the Influx Line Protocol (ILP) like so: If there is something wrong with my ilp_msg or the server or the DB, the above code will execute without raising any error. It will log into sdr out (or std err) on the DB. My question: how can I save data to
How to cache individual Django REST API POSTs for bulk_create?
I have a Django REST API endpoint. It receives a JSON payload eg. This is decoded in a views.py function and generates a new database object like so (pseudo code): In tests, it is 20x faster to create a list of x1000 newobjs, then do a bulk create: So, the question is how to save individual POSTs somewhere in Django
Import data from python (probleme with where condition)
I work in Python I have code that allows me to import a dataset that works fine. However in my dataset I have 3 different patients and I would like to import only the patient that interests me (possible by adding the WHERE statement in the SQL query. So the following code works: It return the patient 14 data But
Django Python annotate ManyToMany Relationship with additional information
my problem is the following. I have two models in the database, which I link together using a ManyToMany relationship. For the admin page I currently use “admin.TabularInline” to bind different objects to one via the graphic. I still want to specify an order in the connections, preferably numbers which represent an order for processing. A bit more figuratively described
I need help formating this data
I have data like this The problem is some data is not in the format like this As you can see in the “local,hometown” there are 3 commas, I want to delete one of them so the data become like this This is just an example to the problem in my data there could be more than 3 commas and
How do I get multiple rows from django database?
Hello I am trying to create an employee attendance program and I want to make it so that the employees can see the total hours they worked. This is the code that creating the problem: The error I get is and if I use it shows an error that says Answer You must use filter and iterate over results as
How to get the most liked users in django rest-api
So I have a social media app, where users can like the posts of other users. Now I want to fetch the top 20 users who have received the most number of likes. I am pretty much confused how to query my Likes Model My LIKES MODEL SIMPLIFIED POST MODEL SIMPLIFIED USER MODEL ** My View ** Answer First I