since pd.append
is deprecated, I've migrated in my code all my df = df.append(temp)
to df = pd.concat([df, temp])
Usually, I have processing where I do something like:
out = pd.DataFrame(columns=['some', 'cols'])
for _, temp in df.groupby('key'):
# SOME PROCESSING OF temp df like
# temp = pd.merge(out, temp, on=['some', 'cols'])
out = pd.concat([out, temp]) # before: out = out.append(temp)
Here, since out is an empty df at first but columns are set, it will not keep dtypes from the temp df. For instance, if I have a datetime column, it's converted as object. If I use an empty df without columns, it keeps the dtypes.
Is that expected ? Considering append will be deprecated this has huge impact in all my code.
source https://stackoverflow.com/questions/71242918/pandas-alternative-to-append-change-dtypes
Comments
Post a Comment