<jupyter_start><jupyter_text>ExamplesThis notebook is designed to show how csvObject can work. csvObject is just a simple object base approach to loading ina csv file and using the data. In more complex cases when doing actual data analysis or changing the structure of the file, using [pandas](https://github.com/pandas-dev/pandas) makes much more sense. But if all you want is to have a lightweight way of extracting the data from the csv file parsed into an object with a few basic options without Numpy then this may be of interest.<jupyter_code>from csvObject import CsvObject, write_csv

file_name = "Example Data.csv"
print(f"Loaded {file_name} and setup environment")<jupyter_output>Loaded Example Data.csv and setup environment<jupyter_text>Simple caseIn this case you just pass the path to the csv file that you want to load, which is the only mandatory argument, andthen you can access the files row content by calling the row data property of the class object. If you choose to printthe object, it will return the name of the file, which along side the path can be accessed by their own attributes, aswell as the row dimensions and, if they have been set, column dimensions.<jupyter_code>csv_object = CsvObject("Example Data.csv")
print(csv_object.row_data)
print(csv_object)<jupyter_output>[['Mitten', '17.5', 'Taby', '5550112', 'FALSE'], ['Squitten', 'NA', 'Tortoiseshell', '', 'TRUE']]
Example Data.csv: Rows:5<jupyter_text>HeadersHeaders are loaded and summed to be present by default. You can call the headers property to have the headers returned to you as a list. However if you don't have headers, you can set file_headers to be false so that the first line of datais stored within the row data rather than assigned to headers. In this case you can still call headers, but it will default to Untitled_1 ... Untitled_N etc. You can then reset headers to have a meaningful list of names if you have themon hand, but keep in mind that no checks are placed on new headers so if they are of the wrong dimension that is on you!<jupyter_code># Headers of our previous object, stored as a list
csv_object = CsvObject("Example Data.csv")
header_list = csv_object.headers
print(csv_object.headers)

# Re setting the object, as if there where no headers
csv_object = CsvObject("Example Data.csv", file_headers=False)
print(csv_object.headers)
print(csv_object.row_data)

# Giving the headers meaningful output
csv_object.headers = header_list
print(csv_object.headers)<jupyter_output>['Cat Name', 'Age', 'Breed', 'Owner Number', 'Untitled_5']
['Untitled_1', 'Untitled_2', 'Untitled_3', 'Untitled_4', 'Untitled_5']
[['Cat Name', 'Age', 'Breed', 'Owner Number', ''], ['Mitten', '17.5', 'Taby', '5550112', 'FALSE'], ['Squitten', '10.2', 'Tortoiseshell', '', 'TRUE']]
A<jupyter_text>TypingYou have multiple ways of providing typing to the data, which is designed to be as forgiving as possible. By default,when you do not specify typing, then all data is loaded as strings. If you assign a single type to column_types, thenall data will be set to that type if possible, and set to a string otherwise. CsvObject will by default give you a warning showing you the column-row-value-type error stored as a list of lists. This data can also be retrieved by calling the invalid_type property.If you have knowledge of what the column types will be, you can also pass a list of types, and the data will be loaded via that type. A common reason for typing errors is missing values. If you turn missing_to_zero then any missing values or miss typedvalues, such as "NA", will be set to a float of zero instead. Also if you want to load the data as is and without warnings, you can just turn them off.<jupyter_code>print("# Uniform Typing #")
csv_object = CsvObject("Example Data.csv", column_types=int)
print("")
print(csv_object.row_data)
print(csv_object.invalid_typed)
print("")

print("# List element Typing #")
csv_object = CsvObject("Example Data.csv", column_types=[str, float, str, int, bool])
print(csv_object.row_data)
print("")

print("# List element Typing with missing set to zero #")
csv_object = CsvObject("Example Data.csv", column_types=[str, float, str, float, bool], missing_to_zero=True)
print(csv_object.row_data)
print("")

print("# Turning Warnings off #")
csv_object = CsvObject("Example Data.csv", column_types=[str, float, str, int, bool], print_warnings=False)
print(csv_object.row_data)
print("")<jupyter_output># Uniform Typing #
Warning: The following column-row-value-type where not correct so loaded as strings:
[[1, 2, 'Mitten', <class 'int'>], [1, 3, 'Squitten', <class 'int'>], [2, 2, '17.5', <class 'int'>], [2, 3, 'NA', <class 'int'>], [3, 2, 'Taby', <class 'int'>], [3, 3, 'Tortoiseshell', <class 'int'>], [4, 3, '', <class 'int'>], [5, 2, 'FALSE', <class 'int'>], [5, 3, 'TRUE', <class 'int'>]]

[['Mitten', '17.5', 'Taby', 5550112, 'FALSE'], ['Squitten', 'NA', 'Tortoiseshell', '', 'TRUE']]
[[1, 2, 'Mitten', <class 'int'>], [2, 2, '17.5', <class 'int'>], [3, 2, 'Taby', <class 'int'>], [5, 2, 'FALSE', <class 'int'>], [1, 3, 'Squitten', <class 'int'>], [2, 3, 'NA', <class 'int'>], [3, 3, 'Tortoiseshell', <class 'int'>], [4, 3, '', <class 'int'>], [5, 3, 'TRUE', <class 'int'>]]

# List element Typing #
Warning: The following column-row-value-type where not correct so loaded as strings:
[[2, 3, 'NA', <class 'float'>], [4, 3, '', <class 'int'>]]
[['Mitten', 17.5, 'Taby', 5550112, False], ['Squit[...]<jupyter_text>Column dataYou may also load data in with column data as well as row data by setting set_columns to be True. This is not on by default **and may be slow for very large data sets**. If you ever just print the object, then it will tell you the filename of the file that was loaded, as well as the column dimensions (if set), and row dimensions. If column data has been set, you can also use indexing of the loaded object to return that column of data. The getitem will allow you to pass either the index of the column, or the name of the header of that column. If you ever need the index of a given header, you can also call if from index_from_headers<jupyter_code>csv_object = CsvObject("Example Data.csv", set_columns=True)
print(csv_object.column_data)
print(csv_object)

header_indexing = csv_object['Owner Number']
print(header_indexing)

cat_name_index = csv_object.index_from_headers("Cat Name")
int_indexing = csv_object[cat_name_index]
print(int_indexing)<jupyter_output>[['Mitten', 'Squitten'], ['17.5', 'NA'], ['Taby', 'Tortoiseshell'], ['5550112', ''], ['FALSE', 'TRUE']]
Example Data.csv: Column:2 by Rows:5
['5550112', '']
['Mitten', 'Squitten']
{'fraction_non_alphanumeric': 0.12254160363086233, 'fraction_numerical': 0.017549167927382755, 'mean_word_length': 5.506889763779528, 'pattern_counts': {'":': 0, '<': 36, '<?xml version=': 0, '>': 36, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '455869', 'license': 'MIT', 'n_tokens_mistral': 2117, 'n_tokens_neox': 2025, 'n_words': 894, 'path': 'Examples/Examples.ipynb', 'repo_name': 'sbaker-dev/csvObject', 'size': '6610'}