You can download this code by clicking the button below.
This code is now available for download.
This custom function generates a random DataFrame with a specified number of rows and columns, containing data of different types (floats, integers, categories, colors, and booleans).
Technology Stack : NumPy, Pandas, scikit-learn
Code Type : Custom function
Code Difficulty : Intermediate
import numpy as np
import pandas as pd
from sklearn.model_selection import train_test_split
def generate_random_dataframe(num_rows=100, num_columns=5):
"""
Generates a random dataframe with specified number of rows and columns.
"""
data = {
'A': np.random.rand(num_rows),
'B': np.random.randint(1, 100, size=num_rows),
'C': np.random.choice(['cat', 'dog', 'mouse'], size=num_rows),
'D': np.random.choice(['red', 'green', 'blue'], size=num_rows),
'E': np.random.choice([True, False], size=num_rows)
}
df = pd.DataFrame(data)
return df
# Code Information