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
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
[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
Step by Step Solution
3.47 Rating (150 Votes )
There are 3 Steps involved in it
Firstly Ill assume you meant to provide structured data but it seems there was some formatting issue ... View full answer
Get step-by-step solutions from verified subject matter experts
