I have tried to find an answer to this problem but to no avail. Here's the problem I'm facing -
I have a csv file where some rows have three elements (indicating that they are full) and some other rows that only have one element in them (indicating they are not full and so should be discarded). Here's an example:
Time, Voltage, Charge
A, B, C
D, E, F
G, H, I
J,
K,
L,
As above, I need to remove J, K
and L
from my csv file. So far I've tried this approach (found in another stack overflow thread here):
if any(val not in (None,"") for val in row):
battlog_voltage.append(float(row[1])/1000.0)
row1 is where the empty fields begin as seen beside J, K, L
. However, I get the following error:
File "/home/raghavk/Documents/batterylog.py", line 81, in <module>
mydata = mylog.loadCycleData('battery-2.csv')
File "/home/raghavk/Documents/batterylog.py", line 68, in loadCycleData
battlog_voltage.append(float(row[1])/1000.0)
IndexError: list index out of range
What can I do to solve this problem?