0

I have phone number column in a pandas dataframe and it has some missing values because of which its dtype is float (which I dont want). I want these to be np.int64 dtype.

I've tried fillna with 0 which converts the dtype to int but the problem is because of 0's, rtl_one.count() method is not identifying 0 as missing values which I dont want.

I've also tried converting the column to "str" but the phone numbers are still displaying with a decimal.

Is there any way to keep the missing values a missing and convert the column to INT, so that rtl_one.count() method will work exactly as expected. Please help, thank you.

rtl_one['HOME_PHONE_1\n'].fillna(0).astype(np.int64)

OUTPUT:

           DW_ATH_CHAIN_NBR  DW_ATH_SEQ_NBR HOME_PHONE_1
0             11                 0          5026372971.0
1             12                 0          7348561782.0
2             105                0          9038961433.0
3             123                0          9205853614.0
4             101                1          nan
5             10                 1          nan
6             1018               1          nan

DESIRED OUTPUT: I want HOME_PHONE_1 column to be integer column and when I do rtl_one.count(), it should look give the result like this, counting the values that are non missing.Is there any way to do it, please help.

rtl_one.count()
Out[67]: 
DW_ATH_CHAIN_NBR\n    7
DW_ATH_SEQ_NBR\n      7
HOME_PHONE_1\n        4
dtype: int64 


           DW_ATH_CHAIN_NBR  DW_ATH_SEQ_NBR HOME_PHONE_1
0             11                 0          5026372971
1             12                 0          7348561782
2             105                0          9038961433
3             123                0          9205853614
4             101                1          nan
5             10                 1          nan
6             1018               1          nan
DPs
  • 207
  • 4
  • 10

0 Answers0