How can I start writing a program in python where it reads an excel file with few records and generate more record for testing purpose

54 views Asked by At

I have got a file with 5 rows and multiple columns and that when read by the program it should generate 100 records for example which can then be loaded into database. Format can be excel or csv

1

There are 1 answers

1
mullinscr On

Let's save you have a file file.csv. Read that into a dataframe and sample from it as many times as you need. Write the result to a new dataframe or csv.

import pandas as pd

df = pd.read_csv('file.csv')
new_df = df.sample(n=100, replace=True) # n could be as big as you want

# new df can now be exported
new_df.to_csv('new_df.csv')