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

Question:

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.

Asked By: jscriptor

||

Answers:

You can try this

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

This will create a blank data frame for us.

Answered By: Bhadrinath Vetry
df = df.append(pd.Series(dtype = 'object'), ignore_index=True)
Answered By: L CX

You can add dtype to your code.

pd.Series(dtype='float64')

Answered By: saneryee

If the accepted solution still results in :

‘ValueError: No objects to concatenate’

Try this solution from FutureWarning: on `df['col'].apply(p.Series)` :

(lambda x: pd.Series(x, dtype="float"))
Answered By: Nina van Bruggen
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.