For the below pandas code in jupyter I am trying to get the data type information .tab
in jupyter provides me information that there is two attributes
It has both dtype
and dtypes
import pandas as pd
new_list = [True,False]
new_pd = pd.Series(new_list)
new_pd
As per the documentation both returns data type information
return from both are good and useful
Question is why there is same duplicate attributes . Which one to be used in which scenario or its a don't care anyone can be used ?
In a pd.Series
object there is no difference. However, in pd.DataFrame
objects you only have dtypes
, which is a series with the data type of each column.
The good thing about this is that when you have a series you can treat it mostly uniformly as a NumPy array and use .dtype
(which is a property present in every NumPy array) or as a data frame and use .dtypes
(which is a property present in all Pandas objects). So in principle many functions for NumPy arrays or data frames already work with series out of the box.
You would use dtypes
with a DataFrame
to get the dtype
for each column/Series.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With