A DataFrame is a two-dimensional array. In Data Frame data is stored in table form in rows and columns. Data Frame is size mutable means we can change the size of a DataFrame at any time. Indexes such as rows and columns and potentially columns are of different types.
Example :-
1. Create pandas DataFrame from a list
The DataFrame can be created using a single list or list of lists.
Example 1.
import pandas as pd data= [1,2,3,4,5] df=pd.DataFrame (data) print (df)
its output will be
0 一一一 0 1 1 2 2 3 3 4 4 5
Note:- You can clearly see the result shows only one column whose name is not given by us it is by default 0, and indexes are also provided by default.
Note:- In this output, you can see there are 4 lists and column names are provided “Name” and “Age”. But indexes are provided by default.
2. Creating a DataFrame from a Dictionary of array
All the array must be of the same length. If the index is passed, then the length of the index must be equal to the length of the arrays. If no index is passed, then by default, the index will be range(n), where n is the length of the array.
Note:- You can see there are two Dictionary “Name” and “Age”. but indexes are from values 0,1,2.3.4. They are provided by default using the range(n) function.
Note:- You can see there are three Dictionaries. NaN values are filled in the missing areas. But indexes are provided by default using range(n) function.
Example 2. The following example shows how to create a Data Frame by passing a List of Dictionaries and the row indices.
If you like my post please share it with your friends by simply clicking the below social media button, and don’t forget to comment so we will update ourselves.
Share in a Single Click
One comment
You have accomplished extraordinary work by distributing this article here. It is valuable and advantageous data for us. Continue to redesign our insight by share these kinds of articles.Online Python tutorial
You have accomplished extraordinary work by distributing this article here. It is valuable and advantageous data for us. Continue to redesign our insight by share these kinds of articles.Online Python tutorial