Posts

Showing posts from February, 2021
Image
  Here are different ways to create a dataframe in PYTHON USING PANDAS LIBRARY  code In [2]: # from a Python lis # Import the library - in this case pandas import pandas as pd # create and initialize a list of multiple lists multilist = [[ 'george' , 2 ], [ 'peter' , 25 ], [ 'alice' , 24 ]] # Create DataFrame df = pd . DataFrame ( multilist , columns = [ 'First Name' , 'Age' ]) # print (show) dataframe. df Out[2]: First Name Age 0 george 2 1 peter 25 2 alice 24 In [3]: # Method #2: Creating DataFrame from dict of an narray/lists # To create DataFrame from a python dictionary of narray/list, all the narray must be of same length. # If index is passed then the length index should be equal to the length of arrays. If no index is passed, then by default, index will # be range(n) where n is the array length. In [3]: # DataFrame from dict narray / lists # Addresses by default import pandas as pd ...