Selecting and deleting random lines from csv in python

Asked

Viewed 153 times

1

I need to make a small script in python that meets the following requirements:

  • Open a csv file;
  • Delete first row and first column from reading as it contains information that will not be needed in this computation itself;
  • Randomly select a number x of "lines" or "cells" from the file, where x is a value expressed as a percentage of the total number of lines existing in the file and that will be defined by the user;
  • Delete the values of the selected Rows or replace them with a value that can be excluded from a later calculation, such as the character "x", "-", etc.

Any suggestions?

  • I forgot to mention that suggestions can be either 2.7 or 3.x, as long as you specify.

  • May I suggest a logic for you to do this, since I don’t know python... Read line by line from the second and go storing the values in a multidimensional array, from the second information. So far you have "cut" the first line and the first column. It is necessary to calculate how many columns "times" how many rows the array has to know the amount of information to be deleted. Then you continue with logic.

  • 2

    Hello Victor, all right? Welcome to Stack Overflow. In the current format your question is difficult to answer objectively. She’s more like "do it for me" or "tell me what I should do" than a question. I would say that you have a better chance of attracting an answer by starting to code and coming back with a specific technical question. See How to ask a good question? and How to create a Minimum, Complete and Verifiable example? in Help Center

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.