Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to create DataFrame with 100 values consisting of 10 elementary numbers in Python Pandas?

I need to create Data Frame in Python Pandas with 100 rows with random values consisting of 10 elementary numbers.
So as a result I need something like below "col1" has to be as date type string:

col1
---------
1233459857
8463746781
9084756289
...

How can I do that in python pandas ?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

To ensure that values beginning with one or more zeros are properly formatted, we can create values of data type string with zero padding to 10 places:

rng = np.random.default_rng()
df = pd.DataFrame(pd.Series(rng.integers(0, 10**10, size=100)).apply(lambda n: f'{n:0>10}'), columns=['col1'])

Output:

          col1
0   9448137321
1   9080789825
2   0131300041
3   6795692128
4   5236197395
..         ...
95  0541351442
96  6920748551
97  9563382744
98  2385042247
99  3736754262
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading