我用
"""Data taken from https://datos.gob.mx/busca/organization/conapo and
https://es.wikipedia.org/wiki/Anexo:Entidades_federativas_de_M%C3%A9xico_por_superficie,_poblaci%C3%B3n_y_densidad """
total_population_segmentation = pd.read_html('professional_segmentation_mexico.html')
population_segmentation = pd.read_html('population_segmentation.html')
Run Code Online (Sandbox Code Playgroud)
其次是
total_population_segmentation = population_segmentation[2]
total_population_segmentation = total_population_segmentation['Población histórica de México']
total_population_segmentation = total_population_segmentation.drop('Pos',axis=1)
total_population_segmentation = total_population_segmentation.sort_values('Entidad').reset_index().drop('index',axis=1)
Run Code Online (Sandbox Code Playgroud)
因此,我正在使用以下 DataFrame
total_population_segmentation.head(5)
Run Code Online (Sandbox Code Playgroud)
我用过total_population_segmentation.dtypes,我得到了
Entidad object
2010 object
2015 object
2020 object
2025 object
2030 object
dtype: object
Run Code Online (Sandbox Code Playgroud)
我曾经pd.to_numeric(total_population_segmentation['2010'])检查它是否有效,但我得到了
ValueError Traceback (most recent call last)
pandas\_libs\lib.pyx in pandas._libs.lib.maybe_convert_numeric()
ValueError: Unable to parse string "1 195 787"
During handling of the above exception, another exception occurred:
ValueError …Run Code Online (Sandbox Code Playgroud)