I'm reading a bunch of CSV files using dtype to specify the type of data of each column:
dict_tpye = {"columns_1":"int","column_2":"str"}
pd.read_csv(path,dtype=dict_tpye)
the problem I'm facing with at doing this that columns with non-float values have missing rows, which rise and error. How can I handle this?
I'll like to use a default value for such a cases, like a 0 for numeric values and an empty string for names.
Consider the converters argument which uses a dictionary, mapping results of a user-defined function to imported columns. Below user-defined methods uses the built-in
isdigit()that returnsTrueif all characters in string are a digit andFalseif at least one is not; andisalpha()as the string counterpart. Adjust as needed especially with strings as you may allow numbers in its content: