Introduction
This is an article focusing on what it is actually exist in the title of this article. In short, Pandas is a Python library which is very useful to work with data sets. Since it is in the nature of Pandas library to work with data sets, it also provide a feature to be able to create a variable with a specific data structure or data object. There is also an article in the previous one which is discussing about how to handle a certain object. Specifically, it is a variable or an object which has the data type with a certain data structure. In other words, it is one of a collection data type which exist in Pandas library. Just read the article with the title of ‘How to Use Pandas with Series’ in this link.
How to Use Pandas with DataFrame
Without going further, this part will go through the description on the topic of how to use pandas with Dataframe. The beginning for the functionality or the usage with Dataframe using Pandas library is obviously define and print it. That is the most basic usage which is very important for further process. Before going on further, there are several aspect which is very important before several function or usability of the DataFrame data structure is available to be utilized using Pandas library. Those aspects are the preparation or the requirements actually available in the previous article in this link. That previous article has the title of ‘How to Use Pandas’.
How to Define DataFrame Using Pandas
So, continue on from the previous part, this part will continue on the process for defining a variable which is having a DataFrame as the data structure. After ensuring the availability of Pandas library, just execute the following steps or sequences in order to define DataFrame to achieve it :
-
Because of the fulfillment of the requirement for having Pandas library, just run Command Prompt as an interface to execute the command. It is obvious to use Command Prompt as the command line interface since in this case, the local device in this example is using Microsoft Windows operating system. Below is the execution of it :
Microsoft Windows [Version 10.0.22000.856] (c) Microsoft Corporation. All rights reserved. C:\Users\Personal>
-
After the appearance of the Command Prompt, in order to start the DataFrame definition, this example will directly use Python command console. So, just type ‘python’ as follows :
Microsoft Windows [Version 10.0.22000.856] (c) Microsoft Corporation. All rights reserved. C:\Users\Personal>python Python 3.10.5 (tags/v3.10.5:f377153, Jun 6 2022, 16:14:13) [MSC v.1929 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>>
-
Soon after entering th python command console, just type ‘import pandas as pd’ in order to import the Pandas library. It is an important as the first to have the Pandas library before defining DataFrame. Look below for the execution example :
Microsoft Windows [Version 10.0.22000.856] (c) Microsoft Corporation. All rights reserved. C:\Users\Personal>python Python 3.10.5 (tags/v3.10.5:f377153, Jun 6 2022, 16:14:13) [MSC v.1929 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import pandas as pd >>>
- Continue on the process for defining DataFrame, just execute the following script in the python command console :
Microsoft Windows [Version 10.0.22000.856] (c) Microsoft Corporation. All rights reserved. C:\Users\Personal>python Python 3.10.5 (tags/v3.10.5:f377153, Jun 6 2022, 16:14:13) [MSC v.1929 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import pandas as pd >>> list = [1,2,3,4] >>> list_data_set_dataframe = pd.DataFrame(list)
-
In order to prove back the content of the Series data set, just print it as follows continuing the previous step :
Microsoft Windows [Version 10.0.22000.856] (c) Microsoft Corporation. All rights reserved. C:\Users\Personal>python Python 3.10.5 (tags/v3.10.5:f377153, Jun 6 2022, 16:14:13) [MSC v.1929 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import pandas as pd >>> list = [1,2,3,4] >>> list_data_set_dataframe = pd.DataFrame(list) >>> print(list_data_set_dataframe) 0 0 1 1 2 2 3 3 4 >>>