def fix_columns(df):
"""
Changes DataFrame in-place
"""
# Convert all string columns to str to avoid a PerformanceWarning
for col in _STRING_COLUMNS:
if col not in df:
continue
df[col].fillna('', inplace=True)
df[col] = df[col].astype('str')
# Empty strings have been set to NaN by read_csv. Replacing
# by the empty string avoids problems with groupby, which
# ignores NaN values.
# Columns that have any NaN values in them cannot be converted to
# int due to a numpy limitation.
for col in _INTEGER_COLUMNS:
if col not in df.columns:
continue
if all(df[col].notnull()):
df[col] = df[col].astype(int)
评论列表
文章目录