To add column names to a dataframe in python using Pandas library, you can use the columns
attribute of a dataframe object. Below is an example:
main.py240 chars12 lines
This will output the following dataframe with column names col1
, col2
, and col3
:
main.py80 chars5 lines
In this example, we first created a 3x3 numpy array and then converted it to a Pandas dataframe. We then assigned the column names to the dataframe using the columns
attribute.
gistlibby LogSnag