Pandas Personal Notes Summary

Overview

Summarize the points that you should be careful about when using it for yourself. Will be added sequentially.

Regarding the type of index

When index_col is used when reading CSV, the index type is different from the dtype specification. It seems that it will be decided automatically.

import pandas as pd

#Example) input.csv
#ID,param1,param2
#0001,01,AAA
#0002,02,BBB
#0003,10,CCC

df = pd.read_csv("input.csv", dtype=object, index_col="ID")
#The type is specified as object, but only index becomes int type
#The leading 0 is missing

It seems that it is necessary to specify the index later in order to retain the type.

df = pd.read_csv("input.csv", dtype=object)
df.set_index("ID", inplace=True)
#Now you can keep the original data

Recommended Posts

Pandas Personal Notes Summary
Pandas notes
Python Pandas Data Preprocessing Personal Notes
pandas self-study notes
python personal notes
python pandas notes
missingintegers python personal notes
keyhac Personal settings summary
[Personal notes] Python, Django
Python3 programming functions personal summary
Personal Ubuntu & WSL2 setup summary
python pandas study recent summary
Basic usage of Pandas Summary
[Personal] Java Gold SE7 Exam Range Point Summary [Additional notes]
Jupyter Notebook Magic Command Personal Summary
Pandas
Laplacian eigenmaps with Scikit-learn (personal notes)
Personal notes for python image processing
Grammar summary often used in pandas
Python package management tool personal summary
Minecraft boot options [Linux] Personal notes
(Personal notes) Python metaclasses and metaprogramming
Pandas basics summary link for beginners
Python> Personal Notes> PEP-0008 Summary> Programming Recommendations Section Only / PEP8 Check Tool Trial
Linux, conda, ssh, git related personal notes
[Python] Summary of how to use pandas
WEB scraping with Python (for personal notes)
Summary of methods often used in pandas
Personal notes and links about machine learning ① (Machine learning)
Gaussian process regression with PyMC3 Personal notes