Closed sandeepny441 closed 11 months ago
--------------------------------------LOC
LOC is Label Based Indexing so 1:3 means 1, 2, 3 - INCLUSIVE.
Python is Position based indexing, so 1:3 means 1, 2 -- EXCLUSIVE. when using label-based indexing with. loc, negative indices don't work as they do in standard Python lists.
Range of Rows: How would you use loc to select all rows from index 2 to 5, inclusive, and only columns 'A' and 'B'?
Boolean Conditions with Multiple Columns: How can you use loc to filter rows where column 'A' is greater than 10 and column 'B' is less than 20, and then only retrieve these rows for columns 'A' and 'C'?
Modify Multiple Values: How would you use loc to change all values in column 'D' to 0 where column 'B' is less than 5?
Slice Columns: How can you use loc to select all rows and columns from 'B' to 'D'?
Modify Row Values: How would you use loc to update all the column values in a row with index 3 to a new list of values [10, 20, 30, 40]?
Negate Conditions: How would you use loc to select all rows where column 'A' is not equal to 10 and then only retrieve the values for columns 'C' and 'D'?
Multiple Conditions for Rows and Columns: How would you use loc to select rows where column 'A' is greater than 5 and column 'B' is not equal to 7, and then retrieve columns 'A', 'C', and 'E'?
Set Values Based on Another Column: How would you use loc to set the values in column 'D' to be the same as the values in column 'B' for rows where column 'A' is greater than 10?
Partial String Matching: If column 'E' contains string values, how would you use loc to filter rows where the values in column 'E' start with the letter 'S', and retrieve only column 'A' for those rows?
Using Functions in Conditions: How would you use loc to filter rows based on a custom function applied to one of the columns, and then retrieve specific columns for those rows?