Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23247

I'm trying to read a .dat file with pandas, however it keeps throwing me UnicodeDecodeError [closed]

$
0
0

I'm trying to read a .dat file in my code, and I'm currently using python to do so. I'm very new, so I kind of have no idea what I'm doing. However, whenever I run it, it's throwing me a "UnicodeDecodeError: 'utf-8' codec can't decode byte 0x80 in position 10: invalid start byte". I've tried other ways of opening the file, but it produices 0 byte .csv files. I'm not sure what I should do. I think it may be a problem with my files themselves.

This is the code I'm using to try and open the files, that is throwing the UnicodeDecodeError:

import pandas as pdimport csvdata = pd.read_csv(r'C:\Users\Apex Gamaing PCs\Gamma Lab Python\CS137 Spectrum.dat', delimiter='\t', dtype='float') back = pd.read_csv(r'C:\Users\Apex Gamaing PCs\Gamma Lab Python\background rad 3 7.dat', delimiter='\t', dtype='float')

This is the other code I tired with, that yeilded the 0 byte file:

import csvwith open('CS137 Spectrum.dat') as dat_file, open('CS137 Spectrum.csv', 'w') as csv_file:    Spectrum1 = csv.writer(csv_file)

I need it to open and read my data so that I can then use the rest of the code to fit curves to said data.

EDIT:

It took 3 professors, 2 grad students, and myself, but we figured out the file format the lab computer default saves the data files as is corrupted and unreadable. Got my data back, and now it's readable. Thank you all for your help.


Viewing all articles
Browse latest Browse all 23247

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>