Questions tagged [categorical]

63 questions
3
votes
0 answers

Plot a boolean/qualitative table with R

I am looking for a way to create a table in R for categorical data. The elements in the table should be symbols, and these symbols should be displayed in a legend. This table from the ICILS 2018 report is to illustrate the kind of table I want to…
2
votes
2 answers

Combine multiple categorical columns into one, when each row has only one non-NaN value, in Pandas

I have import pandas as pd import numpy as np df = pd.DataFrame({"x": ["red", "blue", np.nan, np.nan, np.nan, np.nan, np.nan, ], "y": [np.nan, np.nan, np.nan, 'cold', 'warm', np.nan, np.nan, ], "z": [np.nan,…
CPBL
  • 3,783
  • 4
  • 34
  • 44
2
votes
2 answers

How to remove top and bottom percentile values when both categorical and numerical columns exist in R

Consider data frame below df <- data.frame(a=c("Y", "Y","N", "Y", "N", "N"), b = c(200, 1,1.4,1.3,2,1.6), c = c(200,-200,10,12,14,15), d = c("f","f","m", "m","m","m")) a b c d 1 Y 200.0 …
Mathica
  • 1,241
  • 1
  • 5
  • 17
2
votes
3 answers

Add categorical variable based on conditional selections / dataframe masks

I made three conditional selections on my dataframe. So lets say: final_df[(final_df['acceptance_advice'] == 'standard') & (final_df['acceptance'] == 'ok')] final_df[(final_df['acceptance_advice'] == 'not accepted') & (final_df['acceptance'] ==…
noelle
  • 23
  • 3
2
votes
1 answer

Convert numerical to categorical in python pandas

I have a dataset of internet traffic. There is a ports column I want to convert ports to categorical. This is the code I written to it df2.loc[df2['Src Port'] == 443] = 'HTTPS' Now I want to category all rests ports into category called 'other'. So…
2
votes
2 answers

How to replace values in Pandas column with random numbers per unique values (random categorical)?

I have a df with a column that looks like this: id 11 22 22 333 33 333 This column is sensitive data. I want to replace each value with any random number but each random number should be maintain the same number across the same IDs. For…
RustyShackleford
  • 3,462
  • 9
  • 40
  • 81
1
vote
1 answer

Trouble with setting reference category on logistic regression interaction variable

Among the variables in my dataset, I want to test the interaction between two variables- state category and purpose. state.ctgry has two ordinal categories (NDA and Non NDA) Purporse has 5 ordinal categories (Social, Economic, Cultural, Religious…
1
vote
0 answers

I'd like to make the pandas categorical class faster... how?

I am concerned with creating pandas dataframes with billions of rows. These dataframes are instantiated from a numpy array. The trick is that I need to make some columns into a categorical data type. I would like to do this as fast as possible. …
boxblox
  • 21
  • 4
1
vote
0 answers

Keras category predictions always same distribution

New to Keras/Machine Learning. I figure I am making a dumb mistake but I don't know what. I have 3 labels. The training data for each sequence of timesteps is labeled as [1, 0, 0] or [0, 1, 0], or [0, 0, 1]. I always get a distribution that looks…
Pickles
  • 11
  • 1
1
vote
1 answer

How to get the category of a value in pandas

I wonder how I query and get the the category for a given value For example, with the following code I map the four strings to four categories cat_type = pd.api.types.CategoricalDtype(categories=['c1', 'c2', 'c3', 'c4']) Now I want to query and get…
Michael Dorner
  • 17,587
  • 13
  • 87
  • 117
1
vote
1 answer

Type Error: Cannot set item on a categorical with a new category

I need to replace all values in the order column that are not equal to 'no', 'n/a' or 'N/A' by 1.0. I have tried converting it to a categorical variable and set the pre-existing categories as its distinct categories, but still get the same…
Arthur Langlois
  • 137
  • 1
  • 9
1
vote
0 answers

most efficient way of using categorical independent variables in a JAGS bayesian model

I am trying to run a logistic regression model in JAGS, with a binomial response (rather than Bernoulli process) and wish to model month as a categorical variable. I can easily model month as a continuous model: # Priors beta0 ~ dunif(-20,…
Mark
  • 37
  • 1
  • 8
1
vote
2 answers

Grouping data month-wise with Categorical data in pandas

How can I group data into months from dates where a data frame has both categorical and numerical data in pandas. I tried the groupby function but I think it won't work with categorical data. There are multiple values in the categorical column.…
SSRN
  • 35
  • 4
1
vote
1 answer

Convert categorical variable into binary columns in R

I made the stupid mistake of enabling people to select multiple categories in a survey question. Now the data column for this question looks something along the lines of this. respondent answer_openq 1 a 2 a,c 3 b 4 a,d using the…
1
vote
1 answer

How do I get to categorical descriptor in a pandas categorical series?

I'm fairly familiar with pandas categorical dtype. But, I'm having trouble accessing the nice ordered formatting of the categorical dtype at the bottom of a pandas series frame. Note: I realize other questions have been asked that just gets the…
leeprevost
  • 384
  • 1
  • 3
  • 15
1
2 3 4 5