如何导入 NOAA-CRN 数据文件?

How to Import NOAA-CRN Data Files?

我下载了 .txt 个 NOAA-CRN 数据文件,在删除我不感兴趣的数据并另存为 .csv 后,它看起来像:

4           5           10
LST_DATE    LST_TIME    T_HR_AVG
YYYYMMDD    HHmm         Celsius
20150101    0           20.9
20150101    100         20.9
20150101    200         21
20150101    300         20.7
20150101    400         20.6
20150101    500         20.8

我想读取带有Pandas的文件并将日期和时间转换为以下格式(因为这是其他机构数据使用的格式):

2015-01-01 00:00:00

但我卡住了,似乎没有任何效果。我正在使用此代码读取文件:

parse = (lambda x: pd.datetime.strptime(x, '%Y-%m-%d %H:%m'))
#Import for Everglades City (CRN Station)
Y= pd.read_csv('/file.csv',
              delimiter=',', header = None, engine = 'python',
              skiprows= 3,
              usecols = [0,1,2], 
              parse_dates = [[0,1]], date_parser = parse,
                index_col=0,
               )`

给出:

TypeError: <lambda>() takes 1 positional argument but 2 were given

是否因为 Python 无法处理日期时间格式 YYYYMMDD HHmm 而发生?将不胜感激。

时间格式有问题,可能的解决方法是:

import pandas as pd

temp=u"""4;5;10
LST_DATE,LST_TIME,T_HR_AVG
YYYYMMDD,HHmm,Celsius
20150101,0,20.9
20150101,100,20.9
20150101,200,21
20150101,300,20.7
20150101,400,20.6
20150101,500,20.8"""
#after testing replace 'pd.compat.StringIO(temp)' to 'filename.csv'
#parse = (lambda x: pd.datetime.strptime(x, '%Y%m%d %H'))

df = pd.read_csv(pd.compat.StringIO(temp), 
                 skiprows= 2,
                 usecols = [0,1,2],
                 )

print (df)
   YYYYMMDD  HHmm  Celsius
0  20150101     0     20.9
1  20150101   100     20.9
2  20150101   200     21.0
3  20150101   300     20.7
4  20150101   400     20.6
5  20150101   500     20.8

dates = df.pop('YYYYMMDD').astype(str) + df.pop('HHmm').astype(str).str.zfill(4)
df.index = pd.to_datetime(dates)

print (df)
                     Celsius
2015-01-01 00:00:00     20.9
2015-01-01 01:00:00     20.9
2015-01-01 02:00:00     21.0
2015-01-01 03:00:00     20.7
2015-01-01 04:00:00     20.6
2015-01-01 05:00:00     20.8