How to print pandas column values, names and types?

Print pandas columns

You can export your one or multiple pandas DataFrame column values into a string or list object and print those in your Jupyter Notebook using the following syntax:


# alternatively


Step 1: Create example data

Let’s start by creating some test data that you can use to follow along:

import pandas as pd

month = ['July', 'September', 'November', 'September', 'December']
language = ['Java', 'Java', 'R', 'Javascript', 'R']
salary = [114.0, 166.0, 155.0, 158.0, 131.0]
data = dict(month = month, language = language, salary = salary)
hiring_data = pd.DataFrame(data=data)

Step 2: Get and export column values

You can easily export the values of your month column by slicing a Series object and converting it to a string:


This will return the following string:

0         July
1    September
2     November
3    September
4     December

Step 3: Print column values not index

As you see, the row indices were exported as well. You can get rid of the index when printing by using the following syntax which prints a Numpy array containing the column values:


This returns the following ndarray:

['July' 'September' 'November' 'September' 'December']

Another way to export just the column values is using the index=False parameter of the to_string() function:


You can also print the values directly to a Python list using this code:


Step 4: Export DataFrame column names

You can print your DataFrame column names using the following snippet:


This returns an ndarray that contains the DataFRame column names:

['month' 'language' 'salary']

Step 5: Print pandas column types

In a similar fashion you can get the column data types (dypes of each of your DataFrame columns):

print((to_csv('output.csv', index=False).dtypes).to_string())

This returns the following content:

month        object
language     object
salary      float64

Step 6: Print specific columns with condition

Next we would like to print only values in a column which meet a condition. For example, all relevant values ending with the string ‘ber’. We’ll first slice the Series and then convert it to a string for easier printing.

cond = hiring_data['month'].str.endswith('ber')
print(hiring_data['month'] [cond].to_string())

Step 7: Export your Pandas column without the index

In order to export your dataframe column to a csv file you can use the to_csv Series method as shown in the snippet below.

hiring_data['month'].to_csv('output.csv', index=False)

Step 8: Extract Series values with no index

You can print the values in your Pandas Series without the index using the following snippet:



How to print columns that meet a certain condition?

To get a list of all DataFrame columns which name contains a specific substring, use the following snippet:


How to output the columns names of a multi-index DataFrame?

To get a list of your multi-index frame, use the following code:

print ( multi_index_df_name.columns.levels)

How to get the unique values count in each column?

You can use the nunique() function to obtain a Series containing the number of unique occurrences in a DataFrame columns; for example: