Bin Continuous Values (Age) in df into Discrete Intervals (provide a new column in df called Age_group)
Fantastic news! We've Found the answer you've been seeking!
Question:
Bin Continuous Values (Age) in df into Discrete Intervals (provide a new column in df called Age_group) : ["20-", "20-40", "40-60", "60-80","80+" ]
hint: you can choose to use cut method
Transcribed Image Text:
[1]: bins = [x*20 for x in range(6)] labels =["20-", "20-40", "40-60", "60-80","80+" ] you are not required to use bins and Labels variable below if you do not need it. #provide your answer here [15]: df [15]: Passengerld Survived Pclass Name Sex Age SibSp Parch Ticket Fare Cabin Embarked Tol family no Age group 0 1 0 3 Braund, Mr. Owen Harris male 22.0 1 0 A/S 21171 7.2500 NaN 1 20-40 1 2 1 1 Cumings, Mrs. John Bradley (Florence Briggs Th... female 38.0 1 0 PC 17599 71.2833 CBS c 1 20-40 2 3 1 3 Heikkinen, Miss. Laina female 26.0 0 0 STON/02.3101282 7.9250 NaN S 0 20-40 3 4 1 1 Futrelle, Mrs. Jacques Heath (Lily May Peel) female 35.0 1 0 113803 53.1000 C123 S 1 20-40 4 5 0 3 Allen, Mr. William Henry male 35.0 0 0 373450 8.0500 NaN S 0 20-40 S 6 0 3 6 7 D 1 7 B ° 3 Moran, Mr. James McCarthy, Mr. Timothy J Palsson, Master. Gosta Leonard male NaN 0 0 330877 8.4583 NaN Q 0 NaN male 54.0 0 D 17463 51.8625 E46 S 0 40-60 male 20 3 1 349909 21.0750 NaN S 4 20- 8 9 1 3 Johnson, Mrs. Oscar W (Elisabeth Vilhelmina Berg) female 27.0 0 2 347742 11.1333 NaN S 2 20-40 9 10 1 2 Nasser, Mrs. Nicholas (Adele Achem) female 14.0 1 0 237736 30.0708 NaN C 1 20- 10 11 1 3 Sandstrom, Miss. Marguerite Rut female 4.0 1 1 PP 9549 16.7000 G6 S 2 20- 11 12 1 1 2 2 2 2 2 2 2 2 2 2 2 2 3 12 13 0 3 Saundercock, Mr. William Henry Bonnell, Miss. Elizabeth female 58.0 male 20.0 0 0 113783 26.5500 C103 S 0 40-60 0 0 A/5. 2151 8.0500 NaN S 0 20- 13 14 0 3 Andersson, Mr. Anders Johan male 39.0 1 347082 31.2750 NaN S 6 20-40 14 15 ° 3 Vestrom, Miss. Hulda Amanda Adolfina female 14.0 0 D 350406 7.8542 NaN S 0 20- 15 16 1 2 Hewlett, Mrs. (Mary D Kingcome) female 55.0 0 0 248706 16.0000 NaN S 0 40-60 16 17 0 3 Rice, Master. Eugene male 2.0 4 1 382652 29.1250 NaN Q 5 20- 17 18 1 2 Williams, Mr. Charles Eugene male NaN 0 0 244373 13.0000 NaN S NaN 18 19 ° 3 Vander Planke, Mrs. Julius (Emelia Maria Vande... female 31.0 1 D 345763 18.0000 NaN S 1 20-40 19 20 1 3 Masselmani, Mrs. Fatima female NaN 0 0 2649 7.2250 NaN C 0 NaN 20 21 0 2 Fynney, Mr. Joseph J male 35.0 0 0 239865 26.0000 NaN S 0 20-40 21 22 1 2 Beesley, Mr. Lawrence male 34.0 0 0 248698 13.0000 D56 S 0 20-40 22 23 1 3 McGowan, Miss. Anna "Annie" female 15.0 0 D 330923 8.0292 NaN Q 0 20- 23 24 1 1 Sloper, Mr. William Thompson male 28.0 0 0 113788 35.5000 A6 S 0 20-40 24 25 0 3 Palsson, Miss. Torborg Danira female 8.0 3 1 349909 21.0750 NaN S 4 20- 25 26 1 3 Asplund, Mrs. Carl Oscar (Selma Augusta Emilia female 38.0 1 5 347077 31.3875 NaN S 6 20-40 26 27 27 28 28 29 WNNN ° 3 Emir, Mr. Farred Chehab male NaN 0 0 2631 7.2250 NaN C 0 NaN 0 1 Fortune, Mr. Charles Alexander male 19.0 3 2 19950 263.0000 C23 C25 C27 S 5 8 20- 29 1 3 30 0 3 Todoroff, Mr. Lalio O'Dwyer, Miss. Ellen 'Nellie" female NaN male NaN 0 0 330959 7.8792 NaN Q 0 NaN 0 0 349216 7.8958 NaN S 0 NaN 861 862 ° 2 Giles, Mr. Frederick Edward male 21.0 T 0 28134 11.5000 NaN S 1 20-40 862 863 1 1 Swift, Mrs. Frederick Joel (Margaret Welles Ba... female 48.0 0 0 17466 25.9292 D17 S 0 40-60 863 864 0 3 Sage, Miss. Dorothy Edith "Dolly female NaN 8 2 CA. 2343 69.5500 NaN S 10 NaN 864 865 ° 2 Gill Mr. John William male 24.0 0 0 233866 13.0000 NaN S 0 20-40 865 866 1 2 Bystrom, Mrs. (Karolina) female 42.0 0 0 236852 13.0000 NaN S 0 40-60 866 867 1 2 Duran y More, Miss. Asuncion female 27.0 1 D SC/PARIS 2149 13.8583 NaN с 1 20-40 867 868 0 1 Roebling, Mr. Washington Augustus male 31.0 0 0 PC 17590 50.4958 A24 0 20-40 868 869 ° 3 van Melkebeke, Mr. Philemon male NaN 0 0 345777 9.5000 NaN S 0 NaN [1]: bins = [x*20 for x in range(6)] labels =["20-", "20-40", "40-60", "60-80","80+" ] you are not required to use bins and Labels variable below if you do not need it. #provide your answer here [15]: df [15]: Passengerld Survived Pclass Name Sex Age SibSp Parch Ticket Fare Cabin Embarked Tol family no Age group 0 1 0 3 Braund, Mr. Owen Harris male 22.0 1 0 A/S 21171 7.2500 NaN 1 20-40 1 2 1 1 Cumings, Mrs. John Bradley (Florence Briggs Th... female 38.0 1 0 PC 17599 71.2833 CBS c 1 20-40 2 3 1 3 Heikkinen, Miss. Laina female 26.0 0 0 STON/02.3101282 7.9250 NaN S 0 20-40 3 4 1 1 Futrelle, Mrs. Jacques Heath (Lily May Peel) female 35.0 1 0 113803 53.1000 C123 S 1 20-40 4 5 0 3 Allen, Mr. William Henry male 35.0 0 0 373450 8.0500 NaN S 0 20-40 S 6 0 3 6 7 D 1 7 B ° 3 Moran, Mr. James McCarthy, Mr. Timothy J Palsson, Master. Gosta Leonard male NaN 0 0 330877 8.4583 NaN Q 0 NaN male 54.0 0 D 17463 51.8625 E46 S 0 40-60 male 20 3 1 349909 21.0750 NaN S 4 20- 8 9 1 3 Johnson, Mrs. Oscar W (Elisabeth Vilhelmina Berg) female 27.0 0 2 347742 11.1333 NaN S 2 20-40 9 10 1 2 Nasser, Mrs. Nicholas (Adele Achem) female 14.0 1 0 237736 30.0708 NaN C 1 20- 10 11 1 3 Sandstrom, Miss. Marguerite Rut female 4.0 1 1 PP 9549 16.7000 G6 S 2 20- 11 12 1 1 2 2 2 2 2 2 2 2 2 2 2 2 3 12 13 0 3 Saundercock, Mr. William Henry Bonnell, Miss. Elizabeth female 58.0 male 20.0 0 0 113783 26.5500 C103 S 0 40-60 0 0 A/5. 2151 8.0500 NaN S 0 20- 13 14 0 3 Andersson, Mr. Anders Johan male 39.0 1 347082 31.2750 NaN S 6 20-40 14 15 ° 3 Vestrom, Miss. Hulda Amanda Adolfina female 14.0 0 D 350406 7.8542 NaN S 0 20- 15 16 1 2 Hewlett, Mrs. (Mary D Kingcome) female 55.0 0 0 248706 16.0000 NaN S 0 40-60 16 17 0 3 Rice, Master. Eugene male 2.0 4 1 382652 29.1250 NaN Q 5 20- 17 18 1 2 Williams, Mr. Charles Eugene male NaN 0 0 244373 13.0000 NaN S NaN 18 19 ° 3 Vander Planke, Mrs. Julius (Emelia Maria Vande... female 31.0 1 D 345763 18.0000 NaN S 1 20-40 19 20 1 3 Masselmani, Mrs. Fatima female NaN 0 0 2649 7.2250 NaN C 0 NaN 20 21 0 2 Fynney, Mr. Joseph J male 35.0 0 0 239865 26.0000 NaN S 0 20-40 21 22 1 2 Beesley, Mr. Lawrence male 34.0 0 0 248698 13.0000 D56 S 0 20-40 22 23 1 3 McGowan, Miss. Anna "Annie" female 15.0 0 D 330923 8.0292 NaN Q 0 20- 23 24 1 1 Sloper, Mr. William Thompson male 28.0 0 0 113788 35.5000 A6 S 0 20-40 24 25 0 3 Palsson, Miss. Torborg Danira female 8.0 3 1 349909 21.0750 NaN S 4 20- 25 26 1 3 Asplund, Mrs. Carl Oscar (Selma Augusta Emilia female 38.0 1 5 347077 31.3875 NaN S 6 20-40 26 27 27 28 28 29 WNNN ° 3 Emir, Mr. Farred Chehab male NaN 0 0 2631 7.2250 NaN C 0 NaN 0 1 Fortune, Mr. Charles Alexander male 19.0 3 2 19950 263.0000 C23 C25 C27 S 5 8 20- 29 1 3 30 0 3 Todoroff, Mr. Lalio O'Dwyer, Miss. Ellen 'Nellie" female NaN male NaN 0 0 330959 7.8792 NaN Q 0 NaN 0 0 349216 7.8958 NaN S 0 NaN 861 862 ° 2 Giles, Mr. Frederick Edward male 21.0 T 0 28134 11.5000 NaN S 1 20-40 862 863 1 1 Swift, Mrs. Frederick Joel (Margaret Welles Ba... female 48.0 0 0 17466 25.9292 D17 S 0 40-60 863 864 0 3 Sage, Miss. Dorothy Edith "Dolly female NaN 8 2 CA. 2343 69.5500 NaN S 10 NaN 864 865 ° 2 Gill Mr. John William male 24.0 0 0 233866 13.0000 NaN S 0 20-40 865 866 1 2 Bystrom, Mrs. (Karolina) female 42.0 0 0 236852 13.0000 NaN S 0 40-60 866 867 1 2 Duran y More, Miss. Asuncion female 27.0 1 D SC/PARIS 2149 13.8583 NaN с 1 20-40 867 868 0 1 Roebling, Mr. Washington Augustus male 31.0 0 0 PC 17590 50.4958 A24 0 20-40 868 869 ° 3 van Melkebeke, Mr. Philemon male NaN 0 0 345777 9.5000 NaN S 0 NaN
Expert Answer:
Answer rating: 100% (QA)
Firstly Ill assume you meant to provide structured data but it seems there was some formatting issue ... View the full answer
Related Book For
Microeconomics An Intuitive Approach with Calculus
ISBN: 978-0538453257
1st edition
Authors: Thomas Nechyba
Posted Date:
Students also viewed these programming questions
-
Show a GUI calculator program that will offer the user a button to clear the values, buttons for all digits 0 through 9, as well as the operator buttons for multiplication, division, addition,...
-
This assignment requires you to complete the 2022 tax reporting for a fictional woman named Anna Smith. Question 1 T1 - step 4 - line 66 This is Anna's taxable income Answer: Question 2 T1 - step...
-
The following items were shown on the balance sheet of Herman Corporation on December 31, 2010: Stockholders Equity Paid-In Capital Capital Stock Common stock , $5 par value, 360,000 shares...
-
Alcazarquivir Lda manufactures and sells industrial grinders. The following table presents financial information pertaining to quality in 2014 and 2015 (in ¬000): Required 1 Classify the cost...
-
Determine the slope and displacement at point B. Assume the support at A is a pin and C is a roller. Take E = 29(10 3 ) ksi, I = 300 in 4 . Using Castiglianos theorem. 4 k/ft C De 10 ft 5 ft -
-
Find the equation of motion of the mass shown in Fig. 13.28. Draw the spring-force-versus- \(x\) diagram. -x(t) P sin wot k k 000 00000 KY m 00000 FIGURE 13.28 Mass-spring system of Problem 13.5.
-
Some believe that iGAAP provides too many choices within its accounting guidance. Is this a possible concern in the area of cash flow reporting? Explain.
-
calculate sale proceeds use those information below oard Name of Investment Purchase Price Indie Ruth Asset $50,000,000 Date Acquired 1/3/2021 Sources of Capital $ Amount Ratio % Debt Proceeds $0 0%...
-
How much heat energy (in kj) will be absorbed or released if 8.93 grams of ammonia is produced. State whether the energy will be absorbed or released.
-
Is it necessary to understand the organizations business drivers for BPM and, if so, why?
-
Describe how you ensured traceability between the strategy and the BPM Center of Excellence activities.
-
What are the key risks of the Understand phase?
-
Imagine policymakers in the fictional nation of Pcoria are trying to create a Pcorian National Insurance Program (PNIP) that will bring full insurance to all the citizens of Pcoria. a. Figure 9.21...
-
What are the pros and cons of modeling the current process?
-
Question 1 (a) Discuss any TWO (2) differences between common stock and bonds. (8 marks) (b) Discuss THREE (3) major decisions for which the financial managers are responsible. (6 marks) (c) Suggest...
-
Which of the following gives the range of y = 4 - 2 -x ? (A) (- , ) (B) (- , 4) (C) [- 4, ) (D) (- , 4] (E) All reals
-
In the text, we discussed deadweight losses that arise from wage taxes even when labor supply is perfectly inelastic. We now consider wage subsidies. A: Suppose that the current market wage is w and...
-
Acquisitions of Up-Start Firms by Incumbents: Large software companies often produce a variety of different software, and sometimes a small up-start develops a competing product. The large firm then...
-
For a long period, the U.S. government focused its attempts to meet housing needs among the poor through public housing programs. Eligible families could get on waiting lists to apply for an...
-
Does higher expected inflation increase, decrease, or have no effect on the required rate of return?
-
What methods can a company use to raise capital?
-
Does a company share its risk by issuing equity or debt?
Study smarter with the SolutionInn App