Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

python

pandas

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.

like image 531
jscriptor Avatar asked Jun 02 '20 18:06

jscriptor


People also ask

What is Dtype of empty series?

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

How do you define an empty series in Python?

Series(data=None, index=None, dtype=None, name=None, copy=False, fastpath=False)[source]¶ ... dtype : str, numpy. dtype, or ExtensionDtype, optional Data type for the output Series. If not specified, this will be inferred from data.

How do you create an empty series object?

Answer: An Empty Series is created using the syntax series object = pandas. A one-dimensional named array called Series() can hold any kind of data . The term index refers to all of the axis labels."

What is Astype object?

The astype() function is used to cast a pandas object to a specified data type. Syntax: Series.astype(self, dtype, copy=True, errors='raise', **kwargs) Parameters: Name. Description.


2 Answers

You can try this

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

This will create a blank data frame for us.

like image 70
Bhadrinath Vetry Avatar answered Sep 23 '22 10:09

Bhadrinath Vetry


You can add dtype to your code.

pd.Series(dtype='float64')

like image 33
saneryee Avatar answered Sep 23 '22 10:09

saneryee