categories

Extract value associated with column name on non-zero rows

Extract value associated with column name on non-zero rows Question: I have two dfs(500×100 & 1300×2) and want to create a new column in the first one with which categories that occur on each row. To achieve this I need to fetch the category associated with the column name from second df. There might be …

Total answers: 2

Looking for values from the list among column values

Looking for values from the list among column values Question: 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: …

Total answers: 2

Plotly (Python) – Can plotly inherit categories order setted in pandas?

Plotly (Python) – Can plotly inherit categories order setted in pandas? Question: A simple question: Instead of expliciting categories every time in plotly express, like: fig = px.box(df, x="x_var", y="y_var", category_orders={‘x_var’: ["categorie_1", "categorie_2", … "categorie_n"]}) fig.show() Can plotly inherit categorical order already setted in pandas? like: df[‘x_var’] = pd.Categorical( df[‘x_var’], categories = ["categorie_1", "categorie_2", … …

Total answers: 1

Create a new value output if the values of another column do not match

Create a new value output if the values of another column do not match Question: I am working with some complicated patient health data and would like to simplify categorizing the types of insurance patients use. However, some patients use multiple insurance types to pay for a medical visit (ie Medicare and supplemental insurance). I …

Total answers: 1

Adding a column with one single categorical value to a pandas dataframe

Adding a column with one single categorical value to a pandas dataframe Question: I have a pandas.DataFrame df and would like to add a new column col with one single value "hello". I would like this column to be of dtype category with the single category "hello". I can do the following. df["col"] = "hello" …

Total answers: 3

How to encode categorical values

How to encode categorical values Question: Hi I’m new to python and pandas. I have extracted the unique values of one of the column using pandas. Now after getting the unique values of the column, which are string. [‘Others, Senior Management-Finance, Senior Management-Sales’ ‘Consulting, Strategic planning, Senior Management-Finance’ ‘Client Servicing, Quality Control – Product/ Process, …

Total answers: 2

Python Pandas – Changing some column types to categories

Python Pandas – Changing some column types to categories Question: I have fed the following CSV file into iPython Notebook: public = pd.read_csv("categories.csv") public I’ve also imported pandas as pd, numpy as np and matplotlib.pyplot as plt. The following data types are present (the below is a summary – there are about 100 columns) In …

Total answers: 8