jojorabbit
jojorabbit

Reputation: 47

What is the table() equivalent of R for python?

Say you have a vector(or list, in python) of factors such as

siblings_number = [1, 2 ,3, 2, 1, 0, 0...] 

which is a list of number of siblings for 50 students (who responded to a survey). In R, this would be really easy to tabulate and plot as a barchart. However, I can't seem to find a similar way to do this for Python (a solution I found was to use histogram, which makes me uncomfortable since we are taught to only use histograms for continuous data).

Is there a way around this? Mainly to tabulate factors that is in a long list/ array/ vector, and plot it out if possible via a bar chart.

Upvotes: 0

Views: 196

Answers (1)

ilyankou
ilyankou

Reputation: 1329

Use pandas:

import pandas as pd

siblings_number = [1, 2 ,3, 2, 1, 0, 0]

table = pd.DataFrame(siblings_number)
table.plot.bar()

enter image description here

Upvotes: 1

Related Questions