小编iff*_*_or的帖子

通过python从netCDF中提取数据

我是使用 Python 的新手,也是 NetCDF 的新手,如果我不清楚,请见谅。我有一个包含多个变量的 nc 文件,我需要以新的顺序从这些 nc 文件中提取数据。

我的 nc 文件有 8 个变量(经度、纬度、时间、u10、v10、swh、mwd、mwp),我尝试的逻辑是“如果我输入经度和纬度,我的程序会输出其他变量(u10、v10、swh , mwd, mwp) 按时间排序。” 然后我会将提取的数据放在另一个数据库中。

我测试了我的 nc 文件如下:

import netCDF4
from netCDF4 import Dataset

jan = Dataset('2016_01.nc')
print jan.variables.keys()

lon = jan.variables['longitude']
lat = jan.variables['latitude']
time = jan.variables['time']

for d in jan.dimensions.items():
    print d

lon_array = lon[:]
lat_array = lat[:]
time_array = time[:]

print lon_array
print lat_array
print time_array
Run Code Online (Sandbox Code Playgroud)

部分结果如下

[u'longitude', u'latitude', u'time', u'u10', u'v10', u'swh', u'mwd', u'mwp']

(u'longitude', <type 'netCDF4._netCDF4.Dimension'>: name = 'longitude', size = …
Run Code Online (Sandbox Code Playgroud)

python netcdf netcdf4

4
推荐指数
1
解决办法
1万
查看次数

清理数据帧比loc更有效的方法

我的代码看起来像:

import pandas as pd
df = pd.read_excel("Energy Indicators.xls", header=None, footer=None)
c_df = df.copy()
c_df = c_df.iloc[18:245, 2:]
c_df = c_df.rename(columns={2: 'Country', 3: 'Energy Supply', 4:'Energy Supply per Capita', 5:'% Renewable'})
c_df['Energy Supply'] = c_df['Energy Supply'].apply(lambda x: x*1000000)
c_df.loc[c_df['Country'] == 'Korea, Rep.'] = 'South Korea'
c_df.loc[c_df['Country'] == 'United States of America20'] = 'United States'
c_df.loc[c_df['Country'] == 'United Kingdom of Great Britain and Northern Ireland'] = 'United Kingdom'
c_df.loc[c_df['Country'] == 'China, Hong Kong Special Administrative Region'] = 'Hong Kong'
c_df.loc[c_df['Country'] == …
Run Code Online (Sandbox Code Playgroud)

python dataframe pandas

2
推荐指数
1
解决办法
74
查看次数

为什么(或<falsey value> <falsey value>)返回Clojure中的最终值?

我开始使用Clojure并注意到虽然Clojure的or行为被称为返回第一个truthy值,但传递两个falsey值只or返回第二个值:

user=> (or false false)
false

user=> (or false nil)
nil
Run Code Online (Sandbox Code Playgroud)

我的经验主要是在Python中,其中

>>> False or False
False
Run Code Online (Sandbox Code Playgroud)

这些不相似吗?我理解这是每个http://clojuredocs.org/clojure.core/or的预期行为,并遵循建议查看http://clojuredocs.org/clojure.core/if,但仍不清楚为什么会如此.

boolean clojure

1
推荐指数
1
解决办法
135
查看次数

标签 统计

python ×2

boolean ×1

clojure ×1

dataframe ×1

netcdf ×1

netcdf4 ×1

pandas ×1