Question

In: Computer Science

How to create a compacted data set by combining the columns Old, Older, Young, Younger and...

How to create a compacted data set by combining the columns Old, Older, Young, Younger and place them in into one single new column called age using python pandas.

id Test1 Old Older Young Younger
0.1 1 False False False False
0.2 2 False True True False
0.3 3 True False False False
0.4 4 False False False False

Solutions

Expert Solution

Code:

import pandas as pd
df = pd.DataFrame({'id':[0.1,0.2,0.3,0.4],
                   'Test1':[1,2,3,4],
                   'Old':['False','False','True','False'],
                   'Older':['False','True','False','False'],
                   'Young':['False','True','False','False'],
                   'Younger':['False','False','False','False']
})
print("Before")
print(df.to_string(index=False))
df['age']=df.iloc[:,2:6].apply(lambda x:' '.join(x),axis=1)
print("After")
print(df.to_string(index=False))

Screenshots:


Related Solutions

In the following data set, the columns indicate young adults’ smoking habit, while the rows indicate...
In the following data set, the columns indicate young adults’ smoking habit, while the rows indicate their exercise status. Please conduct a hypothesis to determine whether smoking habit and exercise status are associated. Choose α = 0.05. (Please make sure to check assumptions, if assumptions are not met, you may stop). this q is for a biostatistical subject. Smoking Habit Exercise Status Frequent Some None Total Never 98 86 35 219 Occasion 29 47 23 99 Regular 17 9 17...
There are four numeric columns in R programming language's iris data set. Create a scatter plot...
There are four numeric columns in R programming language's iris data set. Create a scatter plot between the four numeric columns using R programming language and give answers to the following parts. Calculate the correlation between each pair of the four numeric columns in iris. Which pair of variables has the strongest linear relationship? Interpret their ??. Which pair of variables has the weakest linear relationship? Interpret their ??. Which pair(s) of variables can you conclude have a population correlation...
Use Random number generator (under Data Analysis) to simulate the following data set. Create 10 columns,...
Use Random number generator (under Data Analysis) to simulate the following data set. Create 10 columns, each 20 points long and use the following parameters: Number of variables (10), number of data point (20), Distribution (Normal), Mean (40), Standard Deviation (10), Random seed (1234). The data should be in columns: A,B,C,….,I,J. Randomly pick two columns (say Column B and Column H) and perform 2-sided t-test on these two data columns. Record the P-value and repeat this procedure several times (at...
5. How does endurance exercise prescription differ for older adults compared to a prescription for younger...
5. How does endurance exercise prescription differ for older adults compared to a prescription for younger adults? (minimum 7 ways) (3.5 pts) Need help with this question
When the government taxes younger people to pay benefits to older people, how does this affect...
When the government taxes younger people to pay benefits to older people, how does this affect the amount of assistance that younger people might voluntarily choose to offer older people? How does this affect the size of the bequests that older people are likely to leave to their children or grandchildren when they die? How does it affect the decisions of the younger workers about how much leisure they consume (how they spend their disposable income)? How does the promise...
Think about common screenings for women. Explain how screenings differ for younger women and older women,...
Think about common screenings for women. Explain how screenings differ for younger women and older women, and explain the implications of these differences.
Create a hypothetical set of data for a single variable that is on an interval or...
Create a hypothetical set of data for a single variable that is on an interval or ratio scale measurement. There should be 50 scores. And name the variable And create a z score distribution.
How do I create a histogram for the following set of data? Legend: Result (1-100) Age...
How do I create a histogram for the following set of data? Legend: Result (1-100) Age and gender are self explanatory Relationship (are you in a romantic relationship?) Medu (Mothers highest lvl of education. 1= year 10; 2= year 12; 3=bachelor; 4= post grad Lectures (how many lectures missed) Tutorials (How many tutorials missed) RESULT Gender Age Medu Relationship Lectures Tutorials 55 F 20 4 NO 4 3 55 F 19 1 NO 2 3 65 M 18 4 NO...
A data set is provided, entitled oldfaithful_asst, on the duration and height of the Old Faithful...
A data set is provided, entitled oldfaithful_asst, on the duration and height of the Old Faithful geyser in the Yellowstone National Park. Construct a scatterplot using Excel or any software (SPSS or Minitab) between the variables “duration” and “height.” Please title the graph “Scatterplot 1 Old Faithful” and create labels for both axes. There seems to be a an outlier in the data set. Although an outlier is not a detriment to the data analysis, as part of an exercise,...
Create a random data set consisting of two different samples, drawn from Census data that contains...
Create a random data set consisting of two different samples, drawn from Census data that contains numeric values - such as age. Show details of the sourcing. State the null and alternate hypothesis in words that apply to the topic you are addressing. Perform a two-sided, two-sample t-test. Explain what you are doing. Show the graph of the test will all features shown and labeled State the conclusion of the test and grounds.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT