DataFrames

A DataFrame is a data structure used to store tabular data available in Python's pandas package. It is one of the most important data structures for algorithms and is used to process traditional structured data. Let's consider the following table:

id name age decision
1 Fares 32 True
2 Elena 23 False
3 Steven 40 True

 

Now, let's represent this using a DataFrame.

A simple DataFrame can be created by using the following code: 

>>> import pandas as pd
>>> df = pd.DataFrame([ ... ['1', 'Fares', 32, True], ... ['2', 'Elena', 23, False], ... ['3', 'Steven', 40, True]]) >>> df.columns = ['id', 'name', 'age', 'decision'] >>> df id name age decision 0 1 Fares 32 True 1 2 Elena 23 False 2 3 Steven 40 True

Note that, in the preceding code, df.column is a list that specifies the names of the columns.

The DataFrame is also used in other popular languages and frameworks to implement a tabular data structure. Examples are R and the Apache Spark framework. 
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.226.185.96