loc[] and iloc[] - Integrated Circuits - - An Online Book - |
||||||||
Integrated Circuits http://www.globalsino.com/ICs/ | ||||||||
================================================================================= | ||||||||
The primary method for retrieving data from a DataFrame involves referencing its labels. Employ the loc attribute, short for location, to indicate the specific rows and columns we wish to access:
The loc attribute accommodates slice notation, allowing the use of a colon to select all rows or columns. Furthermore, you can utilize lists containing labels or a singular column or row name for more targeted selections. It is crucial to know the DataFrame, which can have one or more columns, and a Series. Even when a DataFrame has only a single column, it is still two-dimensional, whereas a Series is one-dimensional. Both the DataFrame and Series possess an index, but only the DataFrame includes column headers. When we select a column as a Series, the column header serves as the Series name. While many functions or methods can be applied to both Series and DataFrames, discrepancies arise in arithmetic calculations. ================================================ Write to a specific cell (loc[]) in a csv file: code: ================================================ loc[] and iloc[], namely explicit index and implicit index (similar to numpy indexing): code: =================================================== Get maximum and minimum value of column and its index in pandas: code: =================================================== Machine learning: KNN algorithm: code: =================================================== Machine learning: KNN algorithm (version 3 -- more functions are added): code: =================================================== Write a single cell with the rules (Add one more cell at the end of a specific column and then write a number into the end of the column) (code): Input csv file (headersOnly.csv): Output (OutputCSV.csv): The code is modified to (for further test): Input (OutputCSV.csv): Output (OutputCSV2.csv): The code is modified to (for further test): Input (OutputCSV2.csv): Output (OutputCSV3.csv): The code is modified to (for further test) (code): Input (OutputCSV3.csv): Output (OutputCSV4.csv): ===================================================
|
||||||||
================================================================================= | ||||||||
|
||||||||