DeprecationWarning: The default dtype for empty Series will be 'object' instead of 'float64' in a future version warning

Viewed 28005

I appending a new row to an existing pandas dataframe as follows:

df= df.append(pd.Series(), ignore_index=True)

This is resulting in the subject DeprecationWarning.

The existing df has a mix of string, float and dateime.date datatypes (8 columns totals).

Is there a way to explicitly specify the columns types in the df.append?

I have looked here and here but I still have no solution. Please advise if there is a better way to append a row to the end of an existing dataframe without triggering this warning.

4 Answers

You can try this

Type_new = pd.Series([],dtype=pd.StringDtype()) 

This will create a blank data frame for us.

You can add dtype to your code.

pd.Series(dtype='float64')

df = df.append(pd.Series(dtype = 'object'), ignore_index=True)
Related