I have this warning when executing my code.
PerformanceWarning: DataFrame is highly fragmented. This is usually the result of calling
frame.insert
many times, which has poor performance. Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, usenewframe = frame.copy()
I’m working with a data frame with a lot of columns (this is the original data I’ve not added those columns) and this is the first colum I add.
df["mapped_column"] = df["column_to_map"].map(map_dict)
This is the line that give me the warning and it’s not inside a loop or anything like that, it’s only called once. map_dict
is a dictionary containning all the values in column_to_map
.
I have read this question and try the suggestions but nothing works (except ignoring the warning of course).
I’ve two questions, what is a fragmented DataFrame?
What I am doing wrong?