DataFrame Is a two-dimensional collection of data . It is a data structure , The data is stored in tabular form . Data sets are arranged in rows and columns ; We can DataFrame Storing multiple datasets in .
We can perform all kinds of arithmetic operations , For example, in DataFrame Add columns to / Row selection and columns / that 's ok .
We can import from external storage DataFrame; These can be stored SQL database ,CSV Documents and Excel file . We can also use lists , Dictionaries and lists from dictionaries, etc .
In this tutorial , We will learn to create in many ways DataFrame. Let's understand these different ways .
Method 1 : Create empty DataFrame
We can create a basic empty DataFrame. Need to call DataFrame Constructor to create DataFrame. Let's understand the following example :
output :
Method 2 : use List establish DataFrame
We can create using a single list or a list of lists DataFrame. Let's understand the following example :
output :
Method 3 : Create using dictionary DataFrame
ndarray/lists of dict Can be used to create DataFrame, All ndarray Must have the same length . By default , The index will be a range (n);
among n Represents the length of the array . Let's understand the following example :
output :
Method IV : Create indexed using arrays DataFrame
Look at the example below :
output :
In the code above , We have defined column names that contain various vehicle names and their ratings . We use arrays to create indexes .
Method 5 : Create from dictionary list DataFrame
We can create a dictionary list by passing it as input data Pandas DataFrame. By default , Column name as key . Let's understand the following example :
output :
Let's learn another example , Create from a list of dictionaries with row and column indexes pandas DataFrame.
output :
Let's take another example of creating a data frame by passing a dictionary and a row and column table :
output :
Method 6 : use zip() Function creation DataFrame
zip() Function to merge two lists . Let's understand the following example .
output :
Method 7 : Create from sequence dictionary DataFrame
You can pass a dictionary to create DataFrame. We can use a dictionary of sequences , The subsequent index is the union of all passed index value sequences . Let's understand the following example :
output :
In this tutorial , We discussed creating DataFrame Different methods of .
Technology
Daily Recommendation