0

I wrote the following code in python to choose only selected rows. However 'activity_url.csv' has blank rows. Hence it is giving me an error. So how do I skip the blank rows?

data = pd.read_csv('activity_url.csv', delimiter=';')
x="http"
url_data=np.array(data[data.iloc[:,1].str.contains(x, na=False)])[:,1]
Moses Koledoye
  • 77,341
  • 8
  • 133
  • 139
Technologic27
  • 341
  • 3
  • 4
  • 13
  • Do you want to skip blanks or remove the entire row? – OneCricketeer Jul 26 '16 at 06:43
  • I wonder what the error says. But how about that solution: If you want to skip all whitespace lines, you should use this test: ' '.isspace() http://stackoverflow.com/questions/18890688/how-to-skip-blank-line-while-reading-csv-file-using-python – user2853437 Jul 26 '16 at 06:44
  • 2
    The [documentation](http://pandas.pydata.org/pandas-docs/stable/generated/pandas.read_csv.html) states that `skip_blank_lines` is set to `True` per default. Hence, blank rows should be skipped anyhow. What exact error do you receive? – Michael Hoff Jul 26 '16 at 06:44
  • Possible duplicate of [python csv reader ignore blank row](http://stackoverflow.com/questions/31508832/python-csv-reader-ignore-blank-row) – Jokab Jul 26 '16 at 06:46
  • @Jokab no, as this is pandas / read_csv :) – Andy Hayden Jul 26 '16 at 07:37

1 Answers1

0

you can try this code:

import pandas as pd
df=pd.read_csv('activity_url.csv')
df=df.dropna()

After execution, you will get dataframe without any blank row.

Chandan
  • 752
  • 6
  • 12