To add a numpy array to a pandas dataframe in Python, you can use the pandas' DataFrame
method along with the numpy.ndarray
method. Here's an example:
main.py358 chars16 lines
This outputs:
main.py102 chars7 lines
In this case, the numpy array is added to the dataframe as a new column with the label 'C'
. You can replace 'C'
with the desired label for your new column.
gistlibby LogSnag