我无法在python中阅读this dat file。
我尝试了以下内容:
url3 = 'https://www2.census.gov/programs-surveys/saipe/datasets/2002/2002-state-and-county/est02all.dat'
import pandas as pd
saipe02 = pd.read_csv(url3, sep='\s+', header=None, skiprows=1)
或者:
import numpy as np
saipe02 = np.fromfile(url3)
但它们不起作用。 只有这段代码有效但我无法将任何分隔符分隔成列。我尝试了很多分隔符,但它不起作用:
saipe02=pd.read_table(url3,header=None)
答案 0 :(得分:1)
saipe02 = pd.read_fwf(url3, header=None)
print (saipe02.head())
0 1 2 3 ... 30 31 32 33
0 0 0 34569951 33912173 ... NaN US est02ALL.dat 29OCT2004
1 1 0 679856 646828 ... NaN AL est02ALL.dat 29OCT2004
2 1 1 4795 3728 ... NaN AL est02ALL.dat 29OCT2004
3 1 3 16175 12558 ... NaN AL est02ALL.dat 29OCT2004
4 1 5 6152 4767 ... NaN AL est02ALL.dat 29OCT2004
[5 rows x 34 columns]