2

I have tried to convert entire data frame to lowercase using below script. But blank will fill with nan, I tried to remove nan by but no use.

data = data.apply(lambda x: x.astype(str).str.lower())
data = data.replace(np.nan, '', regex=True)

How to solve this?

SPy
  • 2,068
  • 4
  • 24
  • 38
  • This should work if you make `regex=False` – A.Kot Sep 19 '17 at 13:54
  • Possible duplicate https://stackoverflow.com/questions/39512002/convert-whole-dataframe-from-lower-case-to-upper-case-with-pandas – Zero Sep 19 '17 at 13:54
  • @Zero, there was issue as blank filling nan, so I asked in new thread – SPy Sep 19 '17 at 13:56
  • @faithon.gvr.py Q1+Q2 is still a duplicate. Both these are answered as separate questions already. See for NaN https://stackoverflow.com/questions/26837998/pandas-replace-nan-with-blank-empty-string – Zero Sep 19 '17 at 13:56
  • @Zero, OK fine. I agree... – SPy Sep 19 '17 at 13:59

1 Answers1

5

You are close - first fillna, then astype and last convert to lowercase:

data = data.fillna('').astype(str).apply(lambda x: x.str.lower())
jezrael
  • 629,482
  • 62
  • 918
  • 895