Selecting a column
Selected a single column from a DataFrame returns a Series (that has the same index as the DataFrame). It is a single dimension of data, composed of just an index and the data. You can also create a Series by itself without a DataFrame, but it is more common to pull them off of a DataFrame.
This recipe examines two different syntaxes to select a single column of data, a Series. One syntax uses the index operator and the other uses attribute access (or dot notation).
How to do it…
- Pass a column name as a string to the indexing operator to select a Series of data:
>>> movies = pd.read_csv("data/movie.csv") >>> movies["director_name"] 0 James Cameron 1 Gore Verbinski 2 Sam Mendes 3 Christopher Nolan 4 Doug Walker ... 4911 Scott Smith 4912 NaN 4913 Benjamin Roberds 4914 Daniel...