🏆 Shape | 🥇 Beats 99.46% | ✨ Most Efficient | ✔ Explained | Python
Proof of 99.46%:\n\n\n# Code:\nPython\nimport pandas as pd\n\ndef getDataframeSize(players: pd.DataFrame) -> List[int]:\n    return list(players.shape)\n    \n\
# Proof of 99.46%:\n![image.png](https://assets.leetcode.com/users/images/a5f29a3a-bfcd-4f8d-917d-cae854ddd91e_1732889229.0720713.png)\n\n# Code:\n```Python\nimport pandas as pd\n\ndef getDataframeSize(players: pd.DataFrame) -> List[int]:\n    return list(players.shape)\n    \n```\n# Approach:\n\n1. **Importing Pandas:**\n   ```python\n   import pandas as pd\n   ```\n   This line imports the Pandas library, which is essential for data manipulation and analysis in Python.\n\n2. **Defining the Function:**\n   ```python\n   def getDataframeSize(players: pd.DataFrame) -> List[int]:\n   ```\n   This defines a function called `getDataframeSize`. It takes one argument `players`, which is expected to be a Pandas DataFrame. The function\'s return type is a list of integers (`List[int]`).\n\n3. **Returning the DataFrame\'s Shape:**\n   ```python\n   return list(players.shape)\n   ```\n   `players.shape` returns a tuple containing the dimensions of the DataFrame, where the first element is the number of rows and the second element is the number of columns. The `list()` function converts this tuple into a list. So, for example, if the DataFrame has 100 rows and 4 columns, `players.shape` would be `(100, 4)`, and `list(players.shape)` would be `[100, 4]`.\n\nIn summary, this function, `getDataframeSize`, returns a list that represents the size (number of rows and columns) of the given DataFrame.\n\n# Complexity:\nThe code you provided has very simple operations, so the time and space complexities are straightforward:\n\n### Time Complexity:\n- **Importing the library**: `import pandas as pd` happens once and is a constant-time operation, so its complexity is \\( O(1) \\).\n- **Defining the function**: This is also a constant-time operation and doesn\'t depend on the size of the data, so its complexity is \\( O(1) \\).\n- **Calling `players.shape`**: Accessing the shape attribute of a DataFrame is done in constant time, \\( O(1) \\).\n- **Converting to a list**: Converting the tuple `(n, m)` (where `n` is the number of rows and `m` is the number of columns) to a list is a constant-time operation, \\( O(1) \\).\n\nSo, the overall **time complexity** of the function `getDataframeSize` is \\( O(1) \\), which means it runs in constant time regardless of the size of the DataFrame.\n\n### Space Complexity:\n- The function only returns a list of two integers, which occupies a fixed amount of space.\n- The space used by the function is independent of the size of the DataFrame.\n\nThus, the **space complexity** of the function is \\( O(1) \\), meaning it uses a constant amount of space regardless of the input size.\n\nIn summary, both the time and space complexities of your code are \\( O(1) \\). This function is very efficient, as it performs a simple, constant-time operation.\n\n![image.png](https://assets.leetcode.com/users/images/74e90715-ee88-4b63-8e11-e52ab3e41e6f_1732889482.9661021.png)\n
['Python', 'Python3', 'Pandas']