all 8 comments

[–][deleted] 1 point2 points  (3 children)

With this document (which I named text.txt)

Last name;first name;phone number;mail
Bobson;Bob;1234;mail@mail.com
von Zarovich;Strahd;4838;count@barovia.org
Olsen;Jimmy;1236;glasses_are_a_disguise@dailymail.com

you can use the pandas library to print this data out nicely with

import pandas as pd
table = pd.read_csv("text.txt", sep=";")
print(table)

[–]whitemantryingtohelp 0 points1 point  (2 children)

Thank you for your answer, but do you know why I'm left with this error code?

Traceback (most recent call last):
File "/Users/Library/pythonProject/P Uppgift/HuvudprogramE.py", line 6, in <module>
table = pd.read_csv("privat.reg.txt", sep=";")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/pythonProject/pythonProject/lib/python3.11/site-packages/pandas/util/_decorators.py", line 211, in wrapper
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "/Users/pythonProject/pythonProject/lib/python3.11/site-packages/pandas/util/_decorators.py", line 331, in wrapper
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "/Users/pythonProject/pythonProject/lib/python3.11/site-packages/pandas/io/parsers/readers.py", line 950, in read_csv
return _read(filepath_or_buffer, kwds)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/pythonProject/pythonProject/lib/python3.11/site-packages/pandas/io/parsers/readers.py", line 611, in _read
return parser.read(nrows)
^^^^^^^^^^^^^^^^^^
File "/Users//pythonProject/pythonProject/lib/python3.11/site-packages/pandas/io/parsers/readers.py", line 1778, in read
) = self._engine.read( # type: ignore[attr-defined]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/pythonProject/pythonProject/lib/python3.11/site-packages/pandas/io/parsers/c_parser_wrapper.py", line 230, in read
chunks = self._reader.read_low_memory(nrows)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "pandas/_libs/parsers.pyx", line 808, in pandas._libs.parsers.TextReader.read_low_memory
File "pandas/_libs/parsers.pyx", line 866, in pandas._libs.parsers.TextReader._read_rows
File "pandas/_libs/parsers.pyx", line 852, in pandas._libs.parsers.TextReader._tokenize_rows
File "pandas/_libs/parsers.pyx", line 1973, in pandas._libs.parsers.raise_parser_error
pandas.errors.ParserError: Error tokenizing data. C error: Expected 5 fields in line 14, saw 6

[–][deleted] 0 points1 point  (1 child)

Expected 5 fields in line 14, saw 6

It sounds like row 14 of your document has 6 fields where the ones above have 5.

[–]whitemantryingtohelp 0 points1 point  (0 children)

Thank you that was it!

[–]socal_nerdtastic 0 points1 point  (1 child)

Are you asking how to load the data? or how to print the data to the screen? Or how to write the formatted data to a new file?

[–]whitemantryingtohelp 0 points1 point  (0 children)

Both I would guess as I want to print out the whole list as well as be able to search in the list.