Package: maguro
MaguroMaguro is a Python-wrapper for DSV files.Other behaviors are similar to a native Python list, the tutorial below only covers add-on features specific to Maguro.Official ReleaseMaguro can now be used on your Python projects through PyPi by running pip command on a Python-ready environment.pip install maguro --upgradeCurrent version is 1.1.0, but more updates are coming soon. This is compatible with Python version 3.9 or with the latest.package importfrom maguro import Magurobasic usagedataset=Maguro("dataset.csv")custom encodingdataset=Maguro("dataset.csv",encoding="utf-8")custom delimiterdataset=Maguro("dataset.tsv",delimiter="\t")clearRemove all items inside the list by usingdataset.clear()method.add itemsUsedataset.append(value)to add new item in the list.add only if uniqueUsedataset.append(value, unique=True)to add if item is not yet in the list.sortingUsedataset.sort()to sort the list alphabetically.reverseUsedataset.reverse()to reverse the list.remove itemUsedataset.pop(index)to to remove the first occurence in the list.to formatted stringReturn a formatted string, concatenated by the specificied delimiter, by usingdataset.pack()method.raw listReturn a raw list (oflistdata type) by usingdataset.unpack()method.loop over itemsforitemindataset:print(item)remove itemRemove existing (or non-existing) value.
Usage:dataset.remove(value)insert itemInsert data at a specific index
Usage:dataset.insert(index, value)load listLoading new data into a Maguro object will replace previous contents.
Usage:dataset.load(iterable)extend listExtending original lists follows the same list syntax.
Usage:dataset.extend(iterable)remove duplicatesMaguro leverages Pythonlist(set())casting to remove duplicates.
Usage:dataset.distinct()Creating 2D arraystest=Maguro("temp/03b-2d.csv",delimiter=",",newline="\n")test.append(["Juan",23,"Male",72,168,False])test.append(["Pedro",22,"Male",68,172,True])test.append(["Maria",19,"Female",56,162,True])Force Quotations on Stringstest=Maguro("temp/9-tab-separated-values.tsv",delimiter="\t",newline="\n",quote_strings=True)test.clear()test.append(["a","b","c","d","e"])test.append(["1","2","3","4","5"])test.append([1,2,3,4,5])print(test.unpack())ConvertYes,y,No, andnto equivalent Boolean data type (run-time only)test=Maguro("temp/04-booleans.csv",delimiter=",",newline="\n",allow_boolean=True)Header methods# Get the headertest=Maguro("temp/12a-header.csv",delimiter=",",newline="\n",quote_strings=True,has_header=True)print(test.get_header())# Replace with new header# equivalent to: test[0] = [*]test=Maguro("temp/12b-header.csv",delimiter=",",newline="\n",quote_strings=True,has_header=True)test.set_header(["earthquakeId","occurred_on","latitude","longitude","depth","magnitude","calculation_method","network_id","place","cause"])print(test[0])# Add new headertest=Maguro("temp/12c-header.csv",delimiter=",",newline="\n",quote_strings=True)test.set_header(["earthquake_id","occurred_on","latitude","longitude","depth","magnitude","calculation_method","network_id","place","cause"])print(test[0])print(test[1])# Remove header if set# exquivalent to: test = test[1:]test=Maguro("temp/13-header.csv",delimiter=",",newline="\n",quote_strings=True,has_header=True)test.behead()print(test[0])Expand all valid child list to max-lengthtest=Maguro("temp/14-expand.csv",delimiter=",",newline="\n")test.clear()test.append(["name","age","gender","address"])test.append(["Juan","22","M"])test.append(["Pedro","21","M","Mars"])test.append(["Maria","18","F","Earth","Blue"])test.append("Soledad")test.expand()print(test.pack())