Skip to content

Instantly share code, notes, and snippets.

@titovanton
Created July 26, 2020 00:25
Show Gist options
  • Select an option

  • Save titovanton/521a310c5da6d4a64f1bc58a5236a2c5 to your computer and use it in GitHub Desktop.

Select an option

Save titovanton/521a310c5da6d4a64f1bc58a5236a2c5 to your computer and use it in GitHub Desktop.
import numpy as np
def csv_strip(reader):
'''
Removes all rows and columns, which have only blank cells.
Takes csv.reader instance.
Returns numpy array of lists
'''
data = np.array(list(reader))
output = data
indx = 0
for item in data:
if not any(item):
output = np.delete(output, indx, 0)
else:
indx += 1
data = np.transpose(output)
output = data
indx = 0
for item in data:
if not any(item):
output = np.delete(output, indx, 0)
else:
indx += 1
return np.transpose(output)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment