To create a dataframe with column names in Python, you can use the pandas library. Pandas provides the DataFrame()
function, which allows you to create a dataframe with specified column names.
Here's an example of how to create a dataframe with column names:
main.py275 chars13 lines
This will output:
main.py112 chars5 lines
In the above code, we first create a dictionary with column names as the keys and data as the values. Then, we pass this dictionary to the DataFrame()
function to create the dataframe. Finally, we print the dataframe to see the result.
Note that you need to have the pandas library installed in order to use the DataFrame function. You can install it using pip install pandas
if you haven't done so already.
gistlibby LogSnag