COMPSCI C8 Chapter 7: Computational & Inferential Thinking: Functions and Tables

29 views2 pages
8 Mar 2017
School
Professor

Document Summary

Structure of a function: def function_name(input1[, input 2,]): Docstring on what function does return modified_input. Variables defined instead the body of the function have a local scope, and cannot be called elsewhere. Good docstrings include a description of a function"s behavior and expectations about its arguments. Use the . apply method to call a function on each element of a column and return an array of modified values table_name. apply(function_name, column_name") Use the . group method to count the number of rows for each category in a column. This call creates a table with two columns: the categories and their counts. The counts may be modified with a second function input (e. g. sum , max , min ) table_name. group( column_name"[, function]) To cross-classify, or classify by two groups, pass a list of column names into the first function input. Cross-classifying by three or more groups isn"t recommended, since the number of possible combinations can become very large-- making the resulting table complex.

Get access

Grade+
$40 USD/m
Billed monthly
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
10 Verified Answers
Class+
$30 USD/m
Billed monthly
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
7 Verified Answers

Related Documents