Package: pandas-prototype
Pandas PrototypeLove torturing data ? Cause if you torture the data it will confess! Feel the data talking to you #AliveData.A package with implementation of famousPandaslibrary in my way , allows you to visualize data using data tables.Requires python version 3.10 or laterGeneral OverviewMakes your data feel alive .You can filter , print , convert and do lot more with this.Uses prettytable , json , json2html like libraries under the hood for better functioning.Made by dev for devs and data scientists ^_^Compatible with python version 3.10 or aboveDependencies :json2html: for converting data_list to html tableprettytable: for printing tables using asciiGetting startedTo install this package use pip command:pipinstallpandas_prototypeThis is an example of how to use DataFrame class to pretty print tables and make your data alive.Declaring a variable which stores the instance of the DataFrame class (i.e. now variable storesDataFrame object)data=DataFrame([{"id":1,"body":"Hello wolrdEnim sunt ex cupidatat occaecat eiusmod aute .","uuid":"ghjk3878j321134","color":"red",},{"id":2,"body":"Ex aute adipisicing esse do excepteur dolore. ","uuid":"eihr8rhre8013nqfwe-9u",},{"id":3,"body":"Elit consectetur nisi esse fugiat anim irure.","uuid":"b08349m320m=-081",},],["uuid","id","data"],indexed=False)Printing the DataFrame object to consoleprint(data)DataFrame Class :This is the main class which is responsible for generating methods and atrributes which can be used for data filetering and other stuff.It takes a list as paramter , this list is then processed by it's initializer where all the magic happens !Constructor parametersDataFrame(data_list,headers,**kwargs)data_list (param1) : The first parameter is the data list which must have a type of list. All the data objects are created from this list.headers (param2) : It is anoptionalparameter which basically controls the order of headers when printed.It must be a list type . By default the order of headers is sorted. To change this behaviour pass a list of headers which are basically the keys present in the data .Example :data=DataFrame([{"id":1,"data":"..."}{"id":2,"data":"..."}],["id","data"])# Try adding data first instead of idIn this above example we are passing the order of the headers in a way theidappears first and all others heads comes after it. In above example if one or more keys are not present then they will be sorted in ascending order and then printed !Note : The list which is passed must contain the exact head as keys of the list otherwise DataFrame will try to create a seperate coloumn for that head leading to corrupting the data.**kwargs : These are optional parameters which can be send to the DataFrame constructor . Right now only one kwarg is supported namedindexedwhich when set to true will print indexes with the DataFrame object.(By default set to false)DataFrame methodsdata.to_list(): returns the current DataFrame object in python list.data.to_json(): converts the current DataFrame object to json format.data.to_html(): converts the current DataFrame object to html table.data.to_csv(): converts the current DataFrame object to csv.data.export(): Exports your current to a file.Export methodThis method when called on the DataFrame instance first converts the DataFrame object to specified format ( defaultjsonformat if not specified ) and then dumps the data to output file whose name is passed as an argument .Example:data=DataFrame(...)data.export(file_name="filename",format="json",directory=".")Note : By default the file is written in current directory. You can change this behaviour by passing directory as kwarg to the method.Data attributesBasics :These are basically the keys common to the all the items passed as a dict wrapped around list , these are generated on the fly and have thier own methods and comparsion operations these can be used to cycle through each element and find out a paricular element which statisfies the condition.NOTE : if one or two elements miss a certain key then the DataFrame initialzer generates it for you which is initialized with a value ofNoneHere's how these are generated :data=DataFrame([{"id":"some_value","__attr":"..."# just an example}])# DataFrame's initializer generates these .id and other attrs automaticallydata.idPrinting the attributes :When a DataFrame attribute is printed it prints out the attributes in indexed order .print(data.id)Data attribute operations & methods :Here are some opertaions or methods you can use or call on attributes inorder to filter your data*list. Remember these operations are methods are called for each item in the data*list and then compared against the statement ... Hence returning a dataframe_dboolobject which when used withdata[_dbool]returns a filtered out items.To print the filtered data_list just use the simple print function . Example print(data)Comparison statements :In general, a comparison statement is simply a statement in which two quantities or values are being compered. So , these are used to compare the attribute values automatically generated by the DataFrame initializer.1. Lesser than (<)With < we can filter out those ids in data with a value lesser than the desired integer. Consider the example below , it returns a new DataFrame object with filtered ids :data[data.id<5]2. Lesser than equal to (<=)With <= we can filter out those ids in data with a value lesser than the desired integer. Consider the example below , it returns a new DataFrame object with filtered ids :data[data.id<=5]3. Greater than (>)With > we can filter out those ids in data with a value greater than the desired integer. Consider the example below , it returns a new DataFrame object with filtered ids :data[data.id>int(5)]4. Greater than equal to (>=)With >= we can filter out those ids in data with a value greater than or equal to the desired integer. Consider the example below , it returns a new DataFrame object with filtered ids :desired_int=1data[data.id>=desired_int]5. Equals (==)With == we can filter out those ids in data with a value equal to the desired left side value. Consider the example below , it returns a new DataFrame object with filtered colors:desired_color="red"x=data[data.color==desired_color]print(x)NOTE : Ifdata.id == 10is prinited then a _dbool object is printed.Using methods on attributes as statements :1. Ends with methodReturns the _dbool object with only those index of color being true which ends the sepcific string or characterdata.color.endswith("i")2. Starts with methodReturns the _dbool object with only those index of color being true which starts the sepcific string or characterval="r"data.color.startswith(val)3. Includes methodReturns the _dbool object with only those index of color being true which includes the sepcific string or characterval="ed"data.color.include(val)Chaining statements (Logical) :1. Logical and (&)Performs basicandoperation ,& comapres two\_dboolobject and returns a new\_dboolobject which can be used against the orignal DataFrame object to get the desired items. Example:# Note : The operator precedence is also important !print(data[(data.id==1)&(data.color.icludes("ed"))])Note : Use bitwise and (&) instead of logical and (and) operator to perform and logic.2. Logical or ( | )Performs basicoroperation ,| comapres two\_dboolobject and returns a new\_dboolobject which can be used against the orignal DataFrame object to get the desired items. Example:# Note : The operator precedence is also important !print(data[(data.id>2)|(data.color.icludes("ed"))])Note : Use bitwise and (&) instead of logical and (and) operator to perform and logic.Inbuilt Objects & Classes:DataFrame boolean :The_dboolsub-class is used to create an object from it which is used for comparsion , logical statements and finally used by DataFrame to print only the values returned trueDataFrame attribute :Thedata.$attris an instance of DataFrame attribute class ( generated at run time )Developer contactEmail:ssanmeeet123@gmail.comFor any quries feel free to contact ^_^Thank you ;-)