Skip to content

Instantly share code, notes, and snippets.

@anxiousmodernman
Created April 21, 2014 23:54
Show Gist options
  • Save anxiousmodernman/11160597 to your computer and use it in GitHub Desktop.
Save anxiousmodernman/11160597 to your computer and use it in GitHub Desktop.
How to import a CSV file in pandas
# cd to a directory with a csv file in it. Any old csv file will do.
# run ipython and type these things at the interactive prompt, line by line:
>>> import pandas as pd
>>> data = pd.read_csv('some_csv.csv') # other arguments to read_csv are available to change the separator char, for example
>>> data
>>> data.keys # access the keys property of the DataFrame object
>>> len(data) # see the length of the DataFrame object
>>> data.some_column.sum() # get the sum of numeric-type columns
>>> data.some_column.count() # get the count of non-null values
@anxiousmodernman
Copy link
Author

The >>> signifies the prompt, so don't type that. For instance, on line 4, just type

import pandas as pd

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment