Let us suppose that we start with a CSV file that has empty rows:
A, B, C 1, 2, 3 |
If you read this file with Pandas library, and look at the content of your dataframe, you have 2 rows including the empty one that has been filled with NAs
>>> import pandas as pd >>> df = pd.read_csv("test.csv", sep=",") >>>> print(df) A B C 0 NaN NaN NaN 1 1 1 1 [2 rows x 3 columns] |
There is no option to ignore the row in the function read_csv, so you need to do it yourself. Hopefully, there is a dropna method that is handy:
df.dropna(how="all", inplace=True) |
Please follow and like us:
2 Responses to pandas.read_csv: how to skip empty lines