0

How do I load an excel file into pandas datatframe using pd.read_excel without loading rows that have na in them?

Or do I have to first load the whole file and then remove them from the dataframe using dropna?

I'm asking specifically for read_excel. I saw the answer for read_csv and pointed to it.

pashute
  • 3,965
  • 3
  • 38
  • 65
  • I dont think its possible. Cant you read the excel first and then drop the nans using `dropna()` – Bharath M Shetty Nov 01 '17 at 14:06
  • Unfortunately, neither `read_excel` nor `read_csv` does not support this feature at this time. – cs95 Nov 01 '17 at 14:07
  • `read_csv` doesn't, but the python `csv` module does, right? @cᴏʟᴅsᴘᴇᴇᴅ – Uvar Nov 01 '17 at 14:10
  • @Bharath Neither of them do – cs95 Nov 01 '17 at 14:11
  • I asked read_excel not read_csv. Now I don't understand the answer. Both don't support this or one of them does. I'm reading from an excel... – pashute Nov 01 '17 at 14:12
  • @Uvar Maybe... I'm not aware. I'm not sure if it's a good idea using the `csv` module to load dataframes... OP wouldn't be worried about this unless they had a lot of data, in which case `csv` would be ill suited. – cs95 Nov 01 '17 at 14:12
  • @pashute I typed in haste - but neither of those functions support that. You will have to load the whole thing and call `df.dropna()`. – cs95 Nov 01 '17 at 14:13
  • You know @pashute ignoring nans while reading excel is computationally expensive than reading them and droping the nans. Maybe thats the reason why they havent kept that feature. So go for the option you currently have. – Bharath M Shetty Nov 01 '17 at 14:13
  • alls nice and well except that the answer in the duplicate is NOT exactly the same as the question. Since I had no idea or thought of opening a csv file. So please reopen and allow me or someone to answer this with the following: Similar to open_csv there is no option to drop na's while reading. You first have to load the dataframe and then can use dropna. See similar question with open_csv. – pashute Nov 02 '17 at 13:50

0 Answers0