Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

pandas

 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?

like image 422
IOzc Avatar asked Oct 24 '25 16:10

IOzc


1 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"))
like image 52
Lazyer Avatar answered Oct 26 '25 10:10

Lazyer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!