I have a CSV file with 3408 rows and 46 columns and I want to fill each of these columns with 0 and 1 randomly but with the limitation of the appearance of the number 1. For example, in column A I have 3408 records but the number 1 should appear in just 15% of the total rows, and in each column, it must be me who gives the percentage of appearance of '1'.
What I have done so far, is I created a CSV file with 3408 rows and 46 columns full fill randomly with '0' and '1' without the percentage,
Any help or suggestion would be great !!
SPEEDING = 15,49%
Driver inattention or decreased alertness in neighborhoods = 13,81%
Pedestrian carelessness when crossing the road = 6.73% .
.
.
# Create 2D Numpy array of 3408 rows and 46 columns,
# filled with random values 0 and 1
random_data = np.random.randint(0,2,size=(3408,46))
# Create a Dataframe with random values
# using 2D numpy Array
df = pd.DataFrame(random_data, columns=['SPEEDING', 'Driver inattention or decreased alertness in neighborhoods',
'Pedestrian carelessness when crossing the road' , 'Unsafe overtaking', 'Loss of vehicle control' ,
'Refusal of priority' , 'Failure to maintain a safe distance' , 'Non-use of crosswalks' ,
'Playing on the road or walking on the side of the road' ,
'Dangerous maneuvers' , 'Drowsiness' , 'Driving without a license' ,
'Driver inattention when passing a motorcycle' , 'Non respect of the direction imposed to the traffic' ,
'Lane change without signalling' , 'Driving under the influence of alcohol or drugs' , 'Non respect of the road signs' ,
'Driver inattention when leaving the parking area' , 'Driver carelessness when reversing' , 'Traffic in the wrong direction' ,
'Non-respect of the stop sign' , 'Unsafe parking or stopping' , 'Dazzle from lights' ,
'Manual use of mobile phone/ Wearing a headset' , 'Pedestrian crossing the railroad track without precaution' ,
'Other Human Factors' , 'Defective tires (burst)' , 'Defective brakes' , 'Mechanical failures' , 'Defective steering system' ,
'Lack of lighting device' , 'Non-regulation lighting device' , 'Overload' , 'Other Vehicle condition Factors' , 'Weather' ,
'Defective road' , 'Animal crossing' , 'Lack of public lighting' , 'Slippery road surface' , 'Bad road design' , 'Potholes' ,
'Glare of the sun' , 'Obstacle on the road' , 'Deformed roadway' ,
'Other State of the road infrastructure and atmospheric conditions' , 'Fatality'])
# Display the Dataframe
print(df)
# Save the Dataframe to a csv file
df.to_csv('test.csv')