I want to build a Pandas Dataframe and all rows should be equal to the column names of df2:
df1 = pd.Dataframe( ???, index=df2.index, columns=df2.columns)
I have tried with this but it doesn't work:
df1 = pd.Dataframe(  np.repeat(df2.columns, df2.shape[0])  , index=df2.index, columns=df2.columns)
                In [135]: df = pd.DataFrame([list('abc')], index=range(5), columns=list('abc'))
In [136]: df
Out[136]: 
   a  b  c
0  a  b  c
1  a  b  c
2  a  b  c
3  a  b  c
4  a  b  c
[5 rows x 3 columns]
Therefore, use:
df1 = pd.Dataframe([df2.columns], index=df2.index, columns=df2.columns)
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With