0
$\begingroup$
Unique ID        Student Name      BMI       LOW BMI        HIGH BMI
HYD_61601_1200  Akshay Kumar Kale   17.0    NON-UNDER BMI   CANCER
YDD_62329_1008  MAMATHA  ERRA      12.9     NON-UNDER BMI   CANCER
HYD_61601_1000  SURESH BATTU       21.49    NON-UNDER BMI   CANCER
HYD_61601_1021  Vishal  Kavali     13.69    NON-UNDER BMI   CANCER
HYD_61601_1212  DIVYATEJA  M       15.5     NON-UNDER BMI   CANCER
MBNR_61413_2003 Aishaarya P        13.39    NON-UNDER BMI   CANCER
MBNR_61413_1230 SUGUNA             21.5     NON-UNDER BMI   CANCER



import numpy as np
import matplotlib.pyplot as plt
import pandas as pd

# Importing the dataset
dataset = pd.read_csv('HB.csv')
dataset.head()
dataset['HB']<12.5
dataset['LOW HB'] = dataset['HB'] < 12.5
dataset['HB']>12.5
dataset['HIGH HB'] = dataset['HB'] > 12.5
temp = {True:'ANEMIA', False:'NON-ANEMIA'}
dataset['LOW HB'] = dataset['LOW HB'].map(temp)
temp = {True:'CANCER', False:'NON-CANCAER'}
dataset['HIGH HB'] = dataset['HIGH HB'].map(temp)

above data and code i just want to know whether i can assign multiple values r not(for example, i want assign to cancer new values like stage 1, stage 2, final stage) if it possible can any suggest me code r condition to be applied

$\endgroup$
3
  • $\begingroup$ Can you be more specific about where you want to add new data. Do you want a new column, or instead of the word CANCER you want a few entries, like (CANCER, stage 1) $\endgroup$
    – n1k31t4
    Oct 8, 2018 at 11:11
  • $\begingroup$ i want new column $\endgroup$
    – chakri
    Oct 8, 2018 at 11:12
  • $\begingroup$ i just want assign new values it can be in new column r any possible way u can suggest me $\endgroup$
    – chakri
    Oct 8, 2018 at 11:15

1 Answer 1

1
$\begingroup$

After you answer in comments:

You can add a new column with either new information (coming from another file or other source), or you can do it based on the existing columns. In fact you are already adding new columns in your code.

I will add a new column called STAGE both ways to give you an example of each.

From static data

I assume you have the stages in a list, like this:

stage_data = ['stage 1', 'final stage', 'stage 1', 'final stage',
              'stage 2','stage 1','stage 2',]

If you have the stages of each of the existing rows, you can add it simply as follows:

dataset['STAGE'] = stage_data

NOTE: The length of the list should match the length of your dataset i.e. the length of the pandas DataFrame. Check it with this:

assert len(dataset) == len(stage_data), "The lengths don't match!!"

From a condition on existing columns

# Make new column simply filled with zeros - we will fill it after
dataset['STAGE'] = np.zeros(len(dataset))

Now you can use conditions on existing columns and fill the rows that match with your corresponding stage:

# assume people with BMI above 25 must be `stage 1`
data[dataset.BMI > 25]['STAGE'] = 'stage 1'

# assume people with BMI below 15 must be `final stage`
dataset[dataset.BMI < 15]['STAGE'] = 'final stage`

# Stupid example to fill the gaps and show how you can use two conditions:
dataset[(dataset.BMI <= 25) & (dataset.BMI >= 15)]['STAGE'] = 'stage 2'
$\endgroup$
2
  • $\begingroup$ actually my data contains unique id,student name ,B.M.I only. $\endgroup$
    – chakri
    Oct 9, 2018 at 7:09
  • $\begingroup$ i have to predict B.M.I is low,high and if it is low r high i have assign multiple diseases to it can suggest me with code are any condition $\endgroup$
    – chakri
    Oct 9, 2018 at 7:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.