Introdution
This is another article where the main point is to show how to get the column size of a DataFrame using Pandas library. In order to get the column size of a DataFrame, the display will be available after the execution of the process of a certain command. The command itself in this context runs Jupyter Notebook. Just execute the Jupyter Notebook as follows via command line :
(myenv) C:\python\data-science>jupyter notebook [I 17:08:28.062 NotebookApp] Serving notebooks from local directory: C:\python\data-science [I 17:08:28.062 NotebookApp] The Jupyter Notebook is running at: [I 17:08:28.067 NotebookApp] http://localhost:8888/?token=4dd9801ef2aacad1d445955b0ae4621b4c669da84c617e7b [I 17:08:28.068 NotebookApp] or http://127.0.0.1:8888/?token=4dd9801ef2aacad1d445955b0ae4621b4c669da84c617e7b [I 17:08:28.070 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation). [C 17:08:28.225 NotebookApp] To access the notebook, open this file in a browser: file:///C:/Users/Personal/AppData/Roaming/jupyter/runtime/nbserver-8796-open.html Or copy and paste one of these URLs: http://localhost:8888/?token=4dd9801ef2aacad1d445955b0ae4621b4c669da84c617e7b or http://127.0.0.1:8888/?token=4dd9801ef2aacad1d445955b0ae4621b4c669da84c617e7b
Get the Column Size of DataFrame using Pandas Library in Jupyter Notebook
After executing the above command to run Jupyter Notebook, the scenario is to get the DataFrame first. The example in this context is available by pulling the data into the DataFrame from a CSV file. As an example, there is an article in this link where the title of it is ‘How to Read CSV File into a DataFrame using Pandas Library in Jupyter Notebook’. Referring to the article, it shows how to retrieve data from a CSV file into a DataFrame. Ffter successfully load the data, just execute the following command to count the column available in the DataFrame :
import pandas as pd data = pd.read_csv("transactions1.csv",sep=";",low_memory=False) data.shape[1]
The command for displaying the total column available in the DataFrame is easy. It is using the ‘shape’ attribute of the DataFrame. The attribute is an array data type containing two elements. The first index is representing the row size. The second index is representing the column size. The example is available in the following image :
The example above show that the column size is 30. It is an output available in the image above after executing the command ‘data.shape[1]’. Furthermore, to view the size of the row of a DataFrame, just refer to the article in this link. It is an article with the title of ‘How to Get the Row Size of DataFrame using Pandas Library in Jupyter Notebook’.
One thought on “How to Get the Column Size of DataFrame using Pandas Library in Jupyter Notebook”