can't add categories to a category dtype in pandas

I have a pandas dataframe with a field called "promo_type" which I converted to categorical by using astype: df[‘promo_type’] = df[‘promo_type’].astype(‘category’) Later on in the code I want to add another category to the field, as follows: df[‘promo_type’].add_categories(‘0’) And I get this error: AttributeError: ‘Series’ object has no attribute ‘add_categories’ I have checked that my… Read More can't add categories to a category dtype in pandas

Fix the middle category in ggplot

I have a bar graph with 3 groups, each with 3 fill categories. I want one category to always be the middle category on the bar graph. dat <- data.frame(fill=c("Category A","Category B","Middle", "Category A","Category C","Middle", "Category B","Category C","Middle"), x=c("A","A","A", "B","B","B", "C","C","C"), y=c(.333,.333,.333, .4,.4,.2, .2,.4,.4)) ggplot(dat,aes(x=x,y=y,fill=fill))+ geom_col() I don’t think this is possible with traditional factor… Read More Fix the middle category in ggplot

Looking for values from the list among column values

So the problem I am facing that I am looking for a solution to do something like this: (general example) def categotizer(value): toys = [‘ball’, ‘bear’, ‘lego’] food = [‘pizza’, ‘ice-cream’, ‘cake’] if value in toys: return ‘toys’ if value in food: return ‘food’ else: return ’empty’ df[‘purchases_category’] = df[‘purchases’].apply(categorizer) On a column which looks… Read More Looking for values from the list among column values

I can't get product vendor id in django

I am working on an e-commerce project. But the product vendor id is not registered in the database. I’ve tried many ways. I would be glad if you help. seller_id always comes empty What are your suggestions? models.py class Product(models.Model): name = models.CharField(verbose_name="Məhsulun adı", max_length=150) description = models.TextField( verbose_name="Məhsul haqda məlumat", null=True) price = models.FloatField(verbose_name="Məhsulun… Read More I can't get product vendor id in django

How do I summarize tags by category in mongodb

I have a collection that is shaped like this: [ { _id: ObjectId("5d8e8c9b8f8b9b7b7a8b4567"), tags: { language: [ ‘en’ ], industries: [ ‘agency’, ‘travel’ ], countries: [ ‘ca’, ‘us’ ], regions: [ ‘north-america’ ], } }, { _id: ObjectId("5d8e8c9b8f8b9b7b7a8b4568"), tags: { language: [ ‘en’, ‘fr’ ], industries: [ ‘travel’ ], countries: [ ‘ca’ ] } },… Read More How do I summarize tags by category in mongodb

Prisma – create Post with N amount of Categories (explicit Many-to-Many)

I have the most basic explicit Many-to-Many relation: model Category { id Int @id @default(autoincrement()) title String @db.VarChar(24) posts PostCategory[] } model Post { id Int @id @default(autoincrement()) title String @db.VarChar(24) categories PostCategory[] } model PostCategory { category Category @relation(fields: [categoryId], references: [id]) categoryId Int post Post @relation(fields: [postId], references: [id]) postId Int @@id([categoryId, postId])… Read More Prisma – create Post with N amount of Categories (explicit Many-to-Many)