Pandas How To Uncategorized How to turn an array into a dataframe

How to turn an array into a dataframe

You can convert a NumPy array to a Pandas DataFrame using the pd.DataFrame constructor:

import numpy as np
import pandas as pd

array = np.array([1, 2, 3, 4, 5])
df = pd.DataFrame(array)

array is the NumPy array to be converted to a DataFrame.
pd.DataFrame(array) creates a new DataFrame with a single column and the same number of rows as the input array.

You can also specify the column names for the DataFrame:

df = pd.DataFrame(array, columns=["column_name"])

columns=[“column_name”] specifies the name of the column in the DataFrame.

See also:
How to remove outliers in Pandas
How to remove outliers in Pandas

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Post