(../) synesthesiam Michael Hansen (../) An Introduction to Pandas Posted: 2013-04-23 | More posts about programming (../categories/programming.html) python (../categories/python.html) When dealing with numeric matrices and vectors in Python, NumPy (http://www.numpy.org/) makes life a lot easier. For more complex data, however, it leaves a lot to be desired. If you're used to working with data frames in R (http://www.r-tutor.com/r-introduction/data- frame), doing data analysis directly with NumPy feels like a step back. Fortunately, some nice folks have written the Python Data Analysis Library (http://pandas.pydata.org/) (a.k.a. pandas). Pandas provides an R-like DataFrame , produces high quality plots with matplotlib (http://matplotlib.org/), and integrates nicely with other libraries that expect NumPy arrays. In this tutorial, we'll go through the basics of pandas using a year's worth of weather data from Weather Underground (http://www.wunderground.com/). Pandas has a lot of functionality, so we'll only be able to cover a small fraction of what you can do. Check out the (very readable) pandas docs (http://pandas.pydata.org/pandas-docs/stable/) if you want to learn more. Getting Started (an-introduction-to-pandas.html#getting-started) Fun with Columns (an-introduction-to-pandas.html#fun-with-columns) Bulk Operations with apply() (an-introduction-to-pandas.html#bulk-operations- with-apply) Handing Missing Values (an-introduction-to-pandas.html#handing-missing-values) Accessing Individual Rows (an-introduction-to-pandas.html#accessing-individual-rows) Filtering (an-introduction-to-pandas.html#filtering) Grouping (an-introduction-to-pandas.html#grouping) Creating New Columns (an-introduction-to-pandas.html#creating-new-columns) Plotting (an-introduction-to-pandas.html#plotting) Getting Data Out (an-introduction-to-pandas.html#getting-data-out) Miscellanea (an-introduction-to-pandas.html#miscellanea) Getting Started Installing pandas should be an easy process if you use pip: For more complex scenarios, please see the installation instructions (http://pandas.pydata.org/pandas-docs/stable/install.html). OK, let's get started by importing the pandas library. Next, let's read in our data (../assets/weather_year.csv). Because it's in a CSV file, we can use pandas' read_csv function to pull it directly into a DataFrame (http://pandas.pydata.org /pandas-docs/stable/dsintro.html#dataframe). We can get a summary of the DataFrame by printing the object. Output: Home (../index.html) Research (../pages /research.html) Pubs/Talks (../pages /pubs_talks.html) Fun Stuff (../pages /fun-stuff.html) About Me (../pages /about- me.html) Tags (../categories /index.html) Archive (../archive.html) My Github (https://github.com /synesthesiam) Artwork (https://github.com /synesthesiam /artwork) (http://creativecommo /licenses /by-nc- sa/2.5/ar/) An Introduction to Pandas | synesthesiam http://synesthesiam.com/posts/an-introduction-to-pandas.html 1 of 27 8/17/2013 9:02 PM
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
(../)synesthesiamMichael Hansen (../)
An Introduction to Pandas
Posted: 2013-04-23 | More posts about programming (../categories/programming.html) python
(../categories/python.html)
When dealing with numeric matrices and vectors in Python, NumPy (http://www.numpy.org/)
makes life a lot easier. For more complex data, however, it leaves a lot to be desired. If
you're used to working with data frames in R (http://www.r-tutor.com/r-introduction/data-
frame), doing data analysis directly with NumPy feels like a step back.
Fortunately, some nice folks have written the Python Data Analysis Library
(http://pandas.pydata.org/) (a.k.a. pandas). Pandas provides an R-like DataFrame , produces
high quality plots with matplotlib (http://matplotlib.org/), and integrates nicely with other
libraries that expect NumPy arrays.
In this tutorial, we'll go through the basics of pandas using a year's worth of weather data
from Weather Underground (http://www.wunderground.com/). Pandas has a lot of
functionality, so we'll only be able to cover a small fraction of what you can do. Check out the
(very readable) pandas docs (http://pandas.pydata.org/pandas-docs/stable/) if you want to
learn more.
Getting Started (an-introduction-to-pandas.html#getting-started)
Fun with Columns (an-introduction-to-pandas.html#fun-with-columns)
Bulk Operations with apply() (an-introduction-to-pandas.html#bulk-operations-