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...
-
Distinguish a demand-pull from a push-through system. Discuss.
-
What are potential acid sulfate soils, where would you find them, and under what circumstances are they likely to cause serious problems?
-
Mrs. Palsgraf was waiting for a train on a platform of a railroad. When a different train came into the station, two men ran to get on that train before it left the station. While one of the men...
-
The city of Merlot operates a central garage through an Internal Service Fund to provide garage space and repairs for all city-owned and -operated vehicles. The Central Garage Fund was established by...
-
Consider the closed system with mass-action rate constants as shown. Suppose the rate constants are (in min-1) k = 0.05, kg = 0.7, k2= 0.005, and k4 = 0.4. ki k3 A B C k2 ka (a) Construct a...
-
In The Other History of Intercultural Performance, Coco Fusco notes that the practice of appropriating and fetishizing the primitive and simultaneously erasing the original source continues into...
-
Ryder Appraisal District Ryder Appraisal District (RAD) is the county agency responsible for property taxation in Ryder County, South Carolina. RAD is charged with the appraisal of property for tax...
-
Wutang takes a regular salary from the business and an annual bonus depending on OTE's financial results and the cash available. His salary was $325,000 in 2020 and $300,000 in 2019. Any other cash...
-
In Sid's Surf Shop, there is a 10-foot-long surf board on legs with swimwear on it near the entrance to the department where surfing merchandise is sold. The surfboard attracts many customers into...
-
FARO Technologies, whose products include portable 3D measurement equipment, recently had 29 million shares outstanding trading at $25 a share. Suppose the company announces its intention to raise...
-
On 1/1/15 the ABC Company purchased a car for $10,000. They paid $2,000 cash and paid the remainder on account. Prepare the journal entry.
-
Design and implement in Verilog ( gate-level modeling ) a 4-bit ALU according to the following specifications: Build a 1-bit ALU for bits 0 to 2 (without the SET line, but including the LESS input)...
-
In Problem use geometric formulas to find the unsigned area between the graph of y = f(x) and the x axis over the indicated interval. f(x) = x + 5; [0, 4]
-
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...
-
What is a business strategy? Do you agree with the definition proposed? Illustrate your answer with examples.
-
Consider one of the following firms. Read the description of a business strategy in the text. Go to the firm's website and use it to gain an understanding of the business strategy. Look at elements...
-
Which quote at the front of the chapter do you find the most insightful? Why? Under what circumstances would its implications not hold?
Study smarter with the SolutionInn App