Technical Article

Python Script to generate test data

,

Very often there is a need to create test data manually. This script will provide a mix of names that will make more sense rather than randomly generating meaningless names.

def GenerateTestData(lstArgs):
  intNumberOfRecordsToGenerate = 50
  lstFirstName = ["Paul","John","Steve","Jane","Ronaldo","Christie","Alex","Elaine","Gloria",
                  "Kim","Steffi","Martina","Bill","Bob","Andre"]
  lstMiddleName = ["Jordan","Hope","Zillah","Jonah","Jesse","Joshua","Levi","Mark","Matthew",
                   "Michael","Philip","Reuben","Simon","Samuel","Seth","Silas","Solomon","Stephen",
                   "Thomas","Zechariah"]
  lstLastName = ["Hanks","Zhang","Balboa","Ford","Shephard","Franz","Prakash","Goop","Ogeriksky",
                 "Paulinette","Garbonza","Pizzat","Tiblace","Oakee","Zianyi"]
  lstDept = ["IT","Sales","Marketing","Finance","HR","Audit","Controls","Operations"]

  intLengthFirstName = len(lstFirstName)
  intLengthMiddleName = len(lstMiddleName)
  intLengthLastName = len(lstLastName)
  intLengthDept = len(lstDept)

  lstFullName,lstDepartment = [],[]
  for intRecord in range(intNumberOfRecordsToGenerate):
    strFirstName = lstFirstName[random.randint(0, intLengthFirstName)-1]
    strMiddleName = lstMiddleName[random.randint(0, intLengthMiddleName)-1]
    strLastName = lstLastName[random.randint(0, intLengthLastName)-1]
    strDept = lstDept[random.randint(0, intLengthDept)-1]

    strFullName = strFirstName + "-" + strMiddleName + " " + strLastName
    lstFullName.append(strFullName)
    lstDepartment.append(strDept)
    print (strFullName)

  dfEmployees = pd.DataFrame()
  dfEmployees["EmployeeId"] = range(1001, intNumberOfRecordsToGenerate+1001)
  dfEmployees["FullName"] = lstFullName
  dfEmployees["Department"] = lstDepartment
  dfEmployees["Age"] = random.sample(range(21, 100), intNumberOfRecordsToGenerate)
  dfEmployees["Salary"] = random.sample(range(12000, 100000), intNumberOfRecordsToGenerate)
  print (dfEmployees)

  return(dfEmployees)

# End GenerateTestData()

Rate

5 (1)

You rated this post out of 5. Change rating

Share

Share

Rate

5 (1)

You rated this post out of 5. Change rating