jscriptor
jscriptor

Reputation: 845

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

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.

Upvotes: 18

Views: 52395

Answers (4)

Nina van Bruggen
Nina van Bruggen

Reputation: 523

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"))

Upvotes: 3

L CX
L CX

Reputation: 71

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

Upvotes: 6

saneryee
saneryee

Reputation: 3405

You can add dtype to your code.

pd.Series(dtype='float64')

Upvotes: 20

Bhadrinath Vetry
Bhadrinath Vetry

Reputation: 194

You can try this

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

This will create a blank data frame for us.

Upvotes: 17

Related Questions