FutureWarning: on `df['col'].apply(p.Series)`

Viewed 131
 FutureWarning: The default dtype for empty Series will be 'object' instead of 'float64' in a future version. Specify a dtype explicitly to silence this warning.

while doing

rc = dataset_ex[column_name].apply(p.Series)

How one woud avoid warning? What does it mean when one df.apply(pd.Series) what's really happening?

2 Answers

This question(DeprecationWarning: The default dtype for empty Series will be 'object' instead of 'float64' in a future version warning) is pretty similar with your question so it'll help you.

You can ignore all python warnings or FutureWarning with the code bellows but it just hides the warning, not solve it.

import warnings
warnings.filterwarnings("ignore")
import warnings
warnings.simplefilter(action='ignore', category=FutureWarning)

Now, default dtype of Series is float64 but It'll be changed to object.

import pandas as pd
print(pd.__version__)  # '1.2.4'
print(pd.Series().dtype)  # dtype('float64') --> dtype('object') in the future

If you define dtype of Series, warning will be disappear.

rc = dataset_ex[column_name].apply(lambda x: pd.Series(x, dtype="float"))

or

rc = dataset_ex[column_name].apply(lambda x: pd.Series(x, dtype="object"))

I got a similar warning, I solved it by inputting the following code at the top of my code

n = np.dtype(dtype='int64')

I hope this helps :)

Related