I want to accomplish a very specific task but I don’t have an idea of how to do it in Python. The task involves importing every
nth row from a CSV file, for example, I want to import every
10th row present in my CSV file. Please provide me with methods and techniques which are available that can solve this problem, also provide some code snippets as it makes it easy to understand. You can use the Boston dataset for your code using the link attached below:
file_link = 'https://tinyurl.com/BostonHousingcsv'
Hey @mubashir_rizvi, NumPy and slicing method can be used for solving this. Here is the code for it:
np.genfromtxt() function is used to load data from a text file, including CSV files, into a NumPy array.
[1: : n] is used to skip the
0th item from the array (which is the column names) and the 3rd argument in the slicer is used as a step interval to get every
nth item which in this case is 10.
- Since we skipped the column names, we specify them when we create a DataFrame using
Hello @mubashir_rizvi , you can do this by using
skiprows argument of
skiprows argument of the
read_csv() function is used to skip and ignore rows while reading a CSV file. Let me share an example code with you.