原创转载请注明出处:https://www.cnblogs.com/agilestyle/p/12244852.html

 

dtype

The data type or dtype is a special object containing the information (or metadata, data about data) the ndarray needs to interpret a chunk of memory as a particular type of data:

NumPy ndarray data type

 

NumPy data types

NumPy ndarray data type

you can use shorthand type code strings to create ndarray

arr = np.array([1.1, 2.2, 3.3], dtype='f8')

 

astype

You can explicitly convert or cast an array from one dtype to another using ndarray’s astype method. 

Calling astype always creates a new array (a copy of the data), even if the new dtype is the same as the old dtype.

integer -> float

NumPy ndarray data type

float -> integer

NumPy ndarray data type

string -> float

NumPy ndarray data type

Note: If casting were to fail for some reason (like a string that cannot be converted to float64), a ValueError will be raised.

 

Reference

Python for Data Analysis Second Edition

 

相关文章:

  • 2021-07-19
  • 2021-08-11
  • 2022-12-23
  • 2022-12-23
  • 2021-06-22
  • 2022-01-28
  • 2022-12-23
  • 2021-10-26
猜你喜欢
  • 2021-07-05
  • 2021-06-23
  • 2021-09-27
  • 2021-08-15
  • 2022-01-27
  • 2021-11-29
  • 2021-08-27
相关资源
相似解决方案