1

here is my dataFrame:

    Ordered  Items       ord_datetime   Delivered At1        Delivered
13   39      2018-01-25    14:11:06    "25-01-2018 16:40 pm"    None
14   20      2018-01-25    10:53:41    "25-01-2018 14:26 pm"    None
15   13      2018-01-22    19:53:26    "22-01-2018 21:09 pm"    None
16   11      2018-01-22    17:41:20                       ""    None

i want delete that empty string , i used many syntax but i don't know , i can't do this

Output:after applying df.head().to_dict()

 {13: ' "25-01-2018 16:40 pm"',
 14: ' "25-01-2018 14:26 pm"',
 15: ' "22-01-2018 21:09 pm"',
 16: ' ""',
 17: ' "21-01-2018 21:56 pm"'}

things i tried

    1. try to find empty string using this ((df1.values == "").sum()) but it returns 0
    1. then replace "" with NaN but it replace all the value NAN

desire output:

13     "25-01-2018 16:40 pm"
14     "25-01-2018 14:26 pm"
15     "22-01-2018 21:09 pm"
17     "21-01-2018 21:56 pm"
Jose
  • 330
  • 1
  • 3
  • 13
  • Do your actual column have quotes? `""` it's hard to tell, because pandas columns don't usually show them. – cs95 Jun 21 '19 at 18:10
  • What does `(df1.values == '""').sum()` return? **Edit** or how about: `(df1.values == "''''").sum()` (cut and paste to try because they *are* different) – pault Jun 21 '19 at 18:11
  • @pault it returns `0` , i tried it – Jose Jun 21 '19 at 18:12
  • @cs95 it my data , that rows contains `""` this kind of entry – Jose Jun 21 '19 at 18:13
  • Does `df[df['col'].astype(bool)]` work? – cs95 Jun 21 '19 at 18:15
  • @ALollz it returns the error `AttributeError: 'str' object has no attribute 'to_numpy' ` – Jose Jun 21 '19 at 18:16
  • @cs95 it returns `TRUE` for all the rows – Jose Jun 21 '19 at 18:18
  • @pault second syntax is also return "Zero" – Jose Jun 21 '19 at 18:22
  • How about `df1.values.str.endswith('""').sum()`? Maybe there are also some spaces in there. It's impossible to tell without a [mcve]. – pault Jun 21 '19 at 18:23
  • This was exactly the point of my first comment, no one is able to figure out what your data actually looks like now. Please [edit] your question to add the output of `df.head().to_dict()` so we can see what it actually looks like (rather than guess from a flimsy reconstruction of the Series repr). – cs95 Jun 21 '19 at 18:30
  • @pault non of this working :( , see i updated question , what it returns after replacing operation – Jose Jun 21 '19 at 18:30
  • @cs95 check it , i added it – Jose Jun 21 '19 at 18:37
  • OK, try `df = df[df['col'].str.replace('"', '').str.strip().astype(bool)]` – cs95 Jun 21 '19 at 18:39
  • @cs95 Thanks Man , done it , this is not a duplicate question... write this into a ANS section – Jose Jun 21 '19 at 18:42
  • It is more or less a duplicate except with the additional complication of those double quotes which should not be there. I have posted an answer [here](https://stackoverflow.com/a/56708633/4909087). – cs95 Jun 21 '19 at 18:56
  • @cs95 ok , next i will take care of it – Jose Jun 21 '19 at 19:08

0 Answers0