Table Utilities

In order to make it easier for you to visualize tables and create graphs, we've created a few utility functions! The following describe what they do and how they work.

visualize_table(table)

This function takes in a table and displays it! For example, the table:

Fruit

Price

"apple"

1.49

"orange"

1.49

"peach"

2.49

Can be written as:

fruit = {
    'fruit': 
        ['apple', 'orange', 'peach'], 
    'price': 
        [1.49, 1.49, 2.49]
}

Calling visualize_table on fruit would produce the following:

>>> visualize_table(fruit)

    fruit  price
0   apple   1.49
1  orange   1.49
2   peach   2.49

bar(table, x, y)

If you want to graph categorical data, you can use the bar function; it produces a bar graph given a table, the x-axis column, and the y-axis column. If the following table is fruit:

Fruit

Price

"apple"

1.49

"orange"

1.49

"peach"

2.49

Calling the bar function would do the following:

>>> fruit = {
    'fruit': 
        ['apple', 'orange', 'peach'], 
    'price': 
        [1.49, 1.49, 2.49]
}
>>> bar(fruit, 'fruit', 'price')
# input 1: the table; input 2: the x-axis column name; 
# input 3: the y-axis column name

line(table, x, y)

If you want to graph two different kinds of numerical data against each other, you can use the line function; it produces a line graph given a table, the x-axis column, and the y-axis column. If the following table is population:

Year

Population

1900

123,432

1905

126,743

1910

134,894

1915

156,483

Calling the line function would do the following:

>>> population = {
    'year': 
        [1900, 1905, 1910, 1915], 
    'population': 
        [123432, 126743, 134894, 156483]
}
>>> line(population, 'year', 'population')
# input 1: the table; input 2: the x-axis column name; 
# input 3: the y-axis column name

Last updated