Jun-11-2020, 02:45 AM
I want to generate the test data in (.csv format) using Python.
Below is my script using pandas but I'm stuck at randomly generating test data for a column called ACTIVE.
1. ACTIVE column should have value only 0 and 1.
2. Also another issue is that how can I have data of array of varying length.
Thank you in advance.
Below is my script using pandas but I'm stuck at randomly generating test data for a column called ACTIVE.
1. ACTIVE column should have value only 0 and 1.
2. Also another issue is that how can I have data of array of varying length.
Thank you in advance.
import pandas as pd import numpy as np import random x = str(input('Enter the date: ')) y = ['1', '0'] data = {'ACCOUNT': ['', 'Enabled', 'Disabled', 'Hold'], 'CUSTOMER NAME': ['Test Name1', 'Test Name2']} df = pd.DataFrame(data, columns=['ACCOUNT NUMBER', 'ACCOUNT', 'CUSTOMER NAME', 'ACTIVE', 'DATE']) df['ACCOUNT NUMBER'] = 123 #(This needs to auto-increment) df['ACCOUNT NUMBER'] = 123 df['ACTIVE'] = random.choice(y) #(how column named active should randomly take value 0 or 1) df['DATE'] = x df.to_csv(r'C:\Users\Test_User\Desktop\TestFolder\TestFile.csv', index=False)
Error:Enter the date: 9/9/2020
Traceback (most recent call last):
File "C:/Users/TestUser/PycharmProjects/TestDataAutomation/Forum.py", line 10, in <module>
df = pd.DataFrame(data, columns=['ACCOUNT NUMBER', 'ACCOUNT', 'CUSTOMER NAME', 'ACTIVE', 'DATE'])
File "C:\Users\ TestUser\AppData\Roaming\Python\Python37\site-packages\pandas\core\frame.py", line 435, in __init__
mgr = init_dict(data, index, columns, dtype=dtype)
File "C:\Users\ TestUser\AppData\Roaming\Python\Python37\site-packages\pandas\core\internals\construction.py", line 228, in init_dict
index = extract_index(arrays[~missing])
File "C:\Users\ TestUser\AppData\Roaming\Python\Python37\site-packages\pandas\core\internals\construction.py", line 365, in extract_index
raise ValueError("arrays must all be same length")
ValueError: arrays must all be same length
Process finished with exit code 1