Pandas Mixed Type to Integer

前端 未结 2 1493
清歌不尽
清歌不尽 2021-01-21 15:06

Given the following data frame:

import pandas as pd
df = pd.DataFrame(
        {\'A\':[\'A\',\'B\',\'C\',\'D\'],
         \'C\':[\'1\',\'12\',\'*\',\'8\']
               


        
2条回答
  •  孤城傲影
    2021-01-21 15:53

    int() is the Python standard built-in function to convert a string into an integer value. Convert the column to int using int().

    For parsing integers instead of floats, you can use the isdigit() function for string objects.

    If you run isdigit() after int(), you can filter the data to rows where the value for column C is an integer.

提交回复
热议问题