How to Create a Dataframe From Two Arrays in Python

To create a dataframe from two arrays in Python, you can use the pandas.DataFrame() function.

The following example shows how to create a dataframe from two arrays in Python.

Using pandas.DataFrame() Function

We can use the pandas.DataFrame() function to create a dataframe from two arrays.

Suppose we have the following arrays:

import pandas as pd
import numpy as np

# Create numpy arrays
array1 = np.array(['2022-01-01', '2022-01-02', '2022-01-03', '2022-01-04', '2022-01-05'])
array2 = np.array([100, 110, 115, 120, 125])

# Create dataframe
df = pd.DataFrame({'Date': array1, 'Values': array2})

# Show dataframe
print(df)

Output: 👇️

         Date  Values
0  2022-01-01     100
1  2022-01-02     110
2  2022-01-03     115
3  2022-01-04     120
4  2022-01-05     125

In this example, we use the pandas.DataFrame() function to create a dataframe df from the numpy arrays array1 and array2.

The output shows the dataframe created from the two arrays.

Conclusion

We can use the pandas.DataFrame() function to create a dataframe from two arrays in Python.