Convert Pandas column containing NaNs to dtype `int` [duplicate]
问题 This question already has answers here : NumPy or Pandas: Keeping array type as integer while having a NaN value (7 answers) Closed 6 months ago . I read data from a .csv file to a Pandas dataframe as below. For one of the columns, namely id , I want to specify the column type as int . The problem is the id series has missing/empty values. When I try to cast the id column to integer while reading the .csv, I get: df= pd.read_csv(\"data.csv\", dtype={\'id\': int}) error: Integer column has NA