I have the following
x= np.arange(80,95,1)
y= np.arange(175,185,1)
I want to create pandas data frame containing x and y?
Use DataFrame.from_records to create a dataframe from different length arrays, and transpose the result if you want the arrays as columns:
pd.DataFrame.from_records([x,y]).T
0 1
0 80.0 175.0
1 81.0 176.0
2 82.0 177.0
3 83.0 178.0
4 84.0 179.0
5 85.0 180.0
6 86.0 181.0
7 87.0 182.0
8 88.0 183.0
9 89.0 184.0
10 90.0 NaN
11 91.0 NaN
12 92.0 NaN
13 93.0 NaN
14 94.0 NaN
import pandas as pd
df = pd.DataFrame(np.column_stack((x, y)), columns=["x", "y"])
There are probably other ways to do this, the DataFrame object can be constructed in a lot of different ways.
Edit: this actually won't work with different shapes of columns, but can be used with columns of the same length
import pandas as pd
df = pd.DataFrame({'x': x, 'y': y})
x and y and with my code he can turn them into a DataFrame.