If I have a csv file like below with blank row
B;D;K;N;M;R
0;2017-04-27 01:35:30;C;3.5;A;01:15:00;23.0
1;2017-04-27 01:37:30;B;3.5;B;01:13:00;24.0
2;2017-04-27 01:39:00;K;3.5;C;00:02:00;99.0
4;2017-04-27 01:39:00;K;3.5;C;00:02:00;99.0
df = pd.read_csv('input.csv',delimiter=';') will give the dataframe ignoring the blank lines.
B D K N M R
0 2017-04-27 01:35:30 C 3.5 A 01:15:00 23.0
1 2017-04-27 01:37:30 B 3.5 B 01:13:00 24.0
2 2017-04-27 01:39:00 K 3.5 C 00:02:00 99.0
4 2017-04-27 01:39:00 K 3.5 C 00:02:00 99.0
Your code works when you use open. Pandas read_csv will convert the csv file into dataframe. You might be confused with one another.
df = open('input.csv')
new_contents = []
for line in df:
if not line.strip():
continue
else:
new_contents.append(line)
df.read_csv(...).dropna()