Thinking in Pandas by Hannah Stepanek
Author:Hannah Stepanek
Language: eng
Format: epub
ISBN: 9781484258392
Publisher: Apress
Listing 4-17Explicitly converting certain columns to datetime objects
Note Listing 4-17 assumes that there are no NaNs or placeholder values in the column. If there are, like in Listing 4-18, na_values must be specified to convert all the placeholder values to NaNs; otherwise, the column will be an object rather than a datetime because the placeholder values will be left as strings.>> data = io.StringIO(
"""
id,birth,height,weight
129237,04/10/1999,5.4,126
123083,unknown,6.1,150
123087,11/23/1989,4.5,111
"""
)
>> df = pd.read_csv(
data,
dtype={
'id': np.int32,
'height': np.float16,
'weight': np.int16},
parse_dates=["birth"],
na_values=["unknown"],
index_col=[0],
)
birth height weight
id
129237 1999-04-10 5.398438 26
123083 NaT 6.101562 150
123083 1989-11-23 6.101562 111
>> df.memory_usage(deep=True)
Index 24
birth 24
height 6
weight 6
>> df.dtypes
age int8
height float16
weight datetime64[ns]
>> df.index.dtype
dtype('int64')
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(8309)
Test-Driven Development with Java by Alan Mellor(6792)
Data Augmentation with Python by Duc Haba(6709)
Principles of Data Fabric by Sonia Mezzetta(6454)
Learn Blender Simulations the Right Way by Stephen Pearson(6360)
Microservices with Spring Boot 3 and Spring Cloud by Magnus Larsson(6228)
Hadoop in Practice by Alex Holmes(5965)
Jquery UI in Action : Master the concepts Of Jquery UI: A Step By Step Approach by ANMOL GOYAL(5813)
RPA Solution Architect's Handbook by Sachin Sahgal(5629)
Big Data Analysis with Python by Ivan Marin(5396)
The Infinite Retina by Robert Scoble Irena Cronin(5316)
Life 3.0: Being Human in the Age of Artificial Intelligence by Tegmark Max(5158)
Pretrain Vision and Large Language Models in Python by Emily Webber(4362)
Infrastructure as Code for Beginners by Russ McKendrick(4127)
Functional Programming in JavaScript by Mantyla Dan(4044)
The Age of Surveillance Capitalism by Shoshana Zuboff(3964)
WordPress Plugin Development Cookbook by Yannick Lefebvre(3840)
Embracing Microservices Design by Ovais Mehboob Ahmed Khan Nabil Siddiqui and Timothy Oleson(3646)
Applied Machine Learning for Healthcare and Life Sciences Using AWS by Ujjwal Ratan(3616)
