[Python] How to create a DataFrame of random integers with Pandas?

Discussão em 'Python' iniciado por Stack, Fevereiro 4, 2025.

  1. Stack

    Stack Membro Participativo

    I know that if I use randn, the following code gives me what I am looking for, but with elements from a normal distribution. But what if I just wanted random integers?

    import pandas as pd
    import numpy as np
    df = pd.DataFrame(np.random.randn(100, 4), columns=list('ABCD'))


    randint works by providing a range, but not an array like randn. So how do I do this with random integers between some range?

    Continue reading...

Compartilhe esta Página