Skip to content
Advertisement

pandas.Dataframe equivalent for Pandas.read_csv converters?

This discussion covers the differences between dtypesand converters in pandas.read_csv function.

I could not find an equivalent to converters for the pandas.DataFrame constructor in the documentation.

If I build a dataframe directly from a list of lists, what would be the best way to mimic the same behavior?

Some made-up example:

JavaScript
JavaScript

output:

JavaScript

What would be the best way to get the same dataframe from a list of lists?

JavaScript

Edit for clarification:

The example dict_converter holds only one function, but the idea is to be able to apply different conversions for multiple columns.

Advertisement

Answer

Change f_population_to_int function for return same value if any error (remove KeyError) and after create DataFrame use Series.apply:

JavaScript

If need dict dict_converters use:

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement