Stop Pandas from converting int to float

前端 未结 3 1303
旧时难觅i
旧时难觅i 2020-12-25 12:52

I have a DataFrame. Two relevant columns are the following: one is a column of int and another is a column of str.

I understa

3条回答
  •  Happy的楠姐
    2020-12-25 13:46

    If you use DataFrame.append to add the data, the dtypes are preserved, and you do not have to recast or rely on object:

    In [157]: df
    Out[157]:
       int   str
    0    0  zero
    
    In [159]: df.append(pd.DataFrame([[1, None]], columns=['int', 'str']), ignore_index=True)
    Out[159]:
       int   str
    0    0  zero
    1    1  None
    

提交回复
热议问题