0

I have a few datasets from which I need just three columns. When I read it with pd.read_csv I receive all rows but all in one single column. I am quite new to python so I don't know how I can seperate the columns.

import pandas as pd
import numpy as np

df = pd.read_csv('daten/DS-MP210218_1_a_000.gmr', sep='\t', header=[48,49])

print(df)

The data looks like this section, but with more in the header and more datapoints.

#[Loops and repeats]
#  Loop A is used: True
#  Loop B is used: False
#  Loop C is used: False
#
#  Loop A Repeat 2 of 3
#
#
#[Data]
#              Number setpoint_Magnetfeld    Strom_Magnetfeld               Field          Resistance
#                                       V                   A                  Oe                 Ohm
            1.000000               -10.0               -12.0         -2244.56743          5.56989894
            2.000000                -9.5               -11.4         -2136.79182          5.58186254
            3.000000                -9.0               -10.8          -2027.4252          5.58087381
            4.000000                -8.5               -10.2         -1915.87704          5.58050978
            5.000000                -8.0                -9.6         -1804.94498          5.58086033
            6.000000                -7.5                -9.0         -1693.91317          5.58040192
            7.000000                -7.0                -8.4         -1582.03764          5.58034799
            8.000000                -6.5                -7.8         -1470.07665          5.58101763
            9.000000                -6.0                -7.2         -1357.12849          5.58076595
           10.000000                -5.5                -6.6          -1245.4909          5.58083769

thank you for your help!

  • Are you sure that your file is tab delimited? There might be a solution here: [How to make separator in pandas read_csv more flexible wrt whitespace, for irregular separators?](https://stackoverflow.com/a/15026839/3279716) – Alex Apr 20 '22 at 13:46
  • 1
    Check the file's delimiter. Probably its different than '\t' – Gabriel Doretto Apr 20 '22 at 13:46
  • 1
    please provide the first few lines of the csv file – mozway Apr 20 '22 at 13:51
  • With `delim_whitespace=True` I receive the IndexError: list index out of range – Wechsler Apr 20 '22 at 14:08
  • These are the first lines of the file: #[Measurement data output file] # file created at 2021-02-18_12:55:46 # #[Configuration dump] # # writeoutput : True – Wechsler Apr 20 '22 at 14:18

1 Answers1

0

They maybe separated by spaces, try this:

df = pd.read_csv('daten/DS-MP210218_1_a_000.gmr', sep='  *', engine='python')
print(df)
NYC Coder
  • 7,424
  • 2
  • 11
  • 24
  • Then I receive the ParserError: Expected 5 fields in line 41, saw 6. Error could possibly be due to quotes being ignored when a multi-char delimiter is used. where line 41 is line 2 in the section of the data – Wechsler Apr 20 '22 at 14:16