It’s a bit hard to give an example without seeing the data structure.
Generally you should write a method (which would then be used as the __getitem__ method), which accepts an index and loads a single sample (data and target).
Usually the file will be (pre-)loaded in the __init__, while each sample will be loaded and transformed in the __getitem__.
To load csv or txt files I would recommend to use e.g. pandas (or any other lib you are more familiar with).