python

Groupby.mean() if condition is true

Groupby.mean() if condition is true Question: I got the following dataframe: index user default_shipping_cost category shipping_cost shipping_coalesce estimated_shipping_cost 0 0 1 1 clothes NaN 1.0 6.0 1 1 1 1 electronics 2.0 2.0 6.0 2 2 1 15 furniture NaN 15.0 6.0 3 3 2 15 furniture NaN 15.0 15.0 4 4 2 15 furniture …

Total answers: 3

Download multiple azure blobs asynchronously

Download multiple azure blobs asynchronously Question: I am trying to improve the speed of downloading blobs from Azure. Using the package examples from azure, I have created my own example. However, it only works for a single file. I want to be able to pass in multiple customers in the form of a customer_id_list(commented out …

Total answers: 1

Django ForeignKey("x") field must be a "x" instance on update

Django ForeignKey("x") field must be a "x" instance on update Question: Django version 4.2.9 I try to fix this : Cannot assign "(‘customer’,)": "Project.customer" must be a "Customer" instance. I have 2 classes, Project and Customer. class Customer(models.Model): customer_name = models.CharField(max_length=50) string = models.CharField(max_length=50) def __str__(self): return f"{self.customer_name}" class Project(models.Model): project_name = models.TextField() project_code = …

Total answers: 1

Generating combinations in pandas dataframe

Generating combinations in pandas dataframe Question: I have a dataset with ["Uni", ‘Region’, "Profession", "Level_Edu", ‘Financial_Base’, ‘Learning_Time’, ‘GENDER’] columns. All values in ["Uni", ‘Region’, "Profession"] are filled while ["Level_Edu", ‘Financial_Base’, ‘Learning_Time’, ‘GENDER’] always contain NAs. For each column with NAs there are several possible values Level_Edu = [‘undergrad’, ‘grad’, ‘PhD’] Financial_Base = [‘personal’, ‘grant’] Learning_Time …

Total answers: 2

Json Schema Validation Decimal Number

Json Schema Validation Decimal Number Question: The following Python script must validate the number of decimal places in the records. In the schema I am trying to define that it has 3 decimal places, using "multipleOf": 0.001. I have a record with 5 decimal places: "scores": [1.12345] It should report an error but it is …

Total answers: 2

Move specific column information to a new row under the current row

Move specific column information to a new row under the current row Question: Consider this df: data = { ‘Name Type’: ["Primary", "Primary", "Primary"], ‘Full Name’: ["John Snow", "Daenerys Targaryen", "Brienne Tarth"], ‘AKA’: ["Aegon Targaryen", None, None], ‘LQAKA’: ["The Bastard of Winterfell", "Mother of Dragons", None], ‘Other’: ["Info", "Info", "Info"]} df = pd.DataFrame(data) I need …

Total answers: 1

Pyright with multiple venv (monorepo)

Pyright with multiple venv (monorepo) Question: Got an issue with pyright on a monorepo: it didn’t recognize classes/functions imported from nearby projects/libraries (get a reportMissingImports). For instance, with this repo structure: . ├── library |   └── src |    └── __init__.py ├── project1 |   └── src |   └── main.py ├── project2 … └── pyproject.toml This …

Total answers: 1

Overriding multiprocessing.queues.Queue put method

Overriding multiprocessing.queues.Queue put method Question: I want to implement a multiprocessing.Queue that does not add an element that already exists. Using Python STL Queue I had no problem, following this response. For multiprocessing I had some issues that I solved thanks to this For that I do the following: from multiprocessing.queues import Queue from multiprocessing …

Total answers: 2