You can download this code by clicking the button below.
This code is now available for download.
This function generates a DataFrame with random integer values, random floating-point numbers, and random categorical values.
Technology Stack : Pandas, NumPy, Numpy random integer, Numpy random float, Numpy random choice
Code Type : The type of code
Code Difficulty : Intermediate
import random
import pandas as pd
import numpy as np
def random_data_generator(num_rows=1000):
"""
Generate random data for a DataFrame.
"""
data = {
'A': np.random.randint(1, 100, num_rows),
'B': np.random.rand(num_rows),
'C': np.random.choice(['foo', 'bar', 'baz'], num_rows)
}
df = pd.DataFrame(data)
return df