Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a new pandas dataframe from shape

Tags:

python

pandas

I have information on total number of rows and number of columns for a new pandas dataframe

import pandas as pd
nRow = 10
nCol = 4

Based on this information I want to create a new dataframe where each element will be filled by 1

Is there any direct method available with pandas to achieve this?

like image 235
Brian Smith Avatar asked Oct 31 '25 07:10

Brian Smith


1 Answers

Another possible solution, which uses np.ones to create an array of ones with which to create the wanted dataframe:

pd.DataFrame(np.ones((nRow,nCol)))
like image 116
PaulS Avatar answered Nov 02 '25 20:11

PaulS



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!