Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

A single-column can be made from a pandas data frame that has n columns by selecting one of the n columns and creating a new data frame with only that column. Here is an example code:

import pandas as pd

# create a data frame with three columns
df = pd.DataFrame({'a': [1, 2, 3], 'b': [4, 5, 6], 'c': [7, 8, 9]})

# select a single column and create a new data frame
single_col_df = df['a']

# print the new data frame
print(single_col_df)

Output:

0    1
1    2
2    3
Name: a, dtype: int64

In this example code, the df data frame has three columns 'a', 'b', and 'c'. The 'a' column is selected by using df['a'] and stored as a new data frame single_col_df. The output shows that the new data frame has only one column 'a' with the same rows and values as the original 'a' column in the df data frame.