Home > Software engineering >  What is the dtype in the return data from loc?
What is the dtype in the return data from loc?

Time:01-17

df = pd.DataFrame([[2, 3], [5, 6], [8, 9]],
     index=['cobra', 'viper', 'sidewinder'],
     columns=['max_speed', 'shield'])
df.loc['viper']

Produces this output

max_speed    5
shield       6
Name: viper, dtype: int64

dtype is 'Data Type', but what does it refer to? The index label, viper, isn't int64.

CodePudding user response:

loc is to access the row and column by its name, the dtype here refer to the dtype of the resulting pd.Series object

Name : series name 

dtype : series data type
df.loc['viper']
max_speed    5
shield       6
Name: viper, dtype: int64
  •  Tags:  
  • Related