From d043a41bc7e2e0ecafc94913653e7400e53c0091 Mon Sep 17 00:00:00 2001 From: Nil-Andreu Date: Fri, 30 Dec 2022 11:31:37 +0100 Subject: [PATCH 1/2] [NEW] Column & Index values --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index cc8d8181c..63bfb0132 100644 --- a/README.md +++ b/README.md @@ -3210,11 +3210,18 @@ a 1 2 b 3 4 ``` +```python + df = pd.DataFrame([[1, 2], [3, 4]], index=['a', 'b'], columns=['x', 'y']) + df.columns # Get the column names + df.index # Get the index values +``` + ```python = DataFrame() # Rows can be either lists, dicts or series. = DataFrame() # Columns can be either lists, dicts or series. ``` +For selection of multiple elements: ```python = .loc[row_key, column_key] # Or: .iloc[row_index, column_index] = .loc[row_key/s] # Or: .iloc[row_index/es] @@ -3222,6 +3229,7 @@ b 3 4 = .loc[row_bools, column_bools] # Or: .iloc[row_bools, column_bools] ``` + ```python = [column_key/s] # Or: .column_key = [row_bools] # Keeps rows as specified by bools. From db1faadb2cc0c68300cbce20d54f4f07f2d42ecb Mon Sep 17 00:00:00 2001 From: Nil-Andreu Date: Fri, 30 Dec 2022 11:42:33 +0100 Subject: [PATCH 2/2] [NEW] Descriptive df --- README.md | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 63bfb0132..4c282cdfc 100644 --- a/README.md +++ b/README.md @@ -3211,9 +3211,11 @@ b 3 4 ``` ```python - df = pd.DataFrame([[1, 2], [3, 4]], index=['a', 'b'], columns=['x', 'y']) - df.columns # Get the column names - df.index # Get the index values +x_col = [1, 3] +y_col = [2, 4] + = pd.DataFrame({'x': x_col, 'y': y_cal}, index=['a', 'b']) +.columns # Get the column names: {x, y} +.index # Get the index values: {a, b} ``` ```python @@ -3221,6 +3223,14 @@ b 3 4 = DataFrame() # Columns can be either lists, dicts or series. ``` +Descriptive information about dataframe: +```python +.head(n=5) # Return first n occurrences +.dtypes # Return data types of each columns +.isna/isnull() # Return empty values in +.describe() # Get statistical description of (both numeric & object) +``` + For selection of multiple elements: ```python = .loc[row_key, column_key] # Or: .iloc[row_index, column_index] @@ -3229,6 +3239,10 @@ For selection of multiple elements: = .loc[row_bools, column_bools] # Or: .iloc[row_bools, column_bools] ``` +For selection of single element: +```python + = .at[row_index, column_key] +``` ```python = [column_key/s] # Or: .column_key @@ -3247,6 +3261,7 @@ For selection of multiple elements: = .sort_index(ascending=True) # Sorts rows by row keys. = .sort_values(column_key/s) # Sorts rows by the passed column/s. ``` +Those methods have optional parameter *inplace*, which would make the changes in the object from they are called and return None. #### DataFrame — Merge, Join, Concat: ```python