Skip to content

Instantly share code, notes, and snippets.

@lightscalar
Last active December 14, 2015 00:39
Show Gist options
  • Select an option

  • Save lightscalar/5001006 to your computer and use it in GitHub Desktop.

Select an option

Save lightscalar/5001006 to your computer and use it in GitHub Desktop.
Useful things related to PANDAS

Useful PANDAS Stuff

Installation & Upgrade

In order to upgrade pandas on OSX (or *NIX), use pip:

sudo pip install pandas --upgrade

Need to do this as a SU.

DataFrame Basics

Now suppose we have a dataframe df. To see a list of the indices, we simply call df.index. To determine the names of the columns, we call df.columns.

Individual columns of a DataFrame can be easily access. Suppose we have a DataFrame called humans:

In [32]: humans
Out[32]: 
   eye color  gender    height     weight
0       blue    male  1.706197  92.625849
1      brown  female  1.600951  74.814092
2       blue    male  1.793095  92.295413
3      brown  female  1.679333  76.535305
4       blue  female  1.468511  79.040913
5      green    male  1.826871  87.132300

We can access a particular column of the DataFrame (DF) by indexing the DF as if it were a dict.

In [33]: humans['eye color']
Out[33]: 
0      blue
1     brown
2      blue
3     brown
4      blue
5     green
6     brown
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment