在对9列数据集的一列使用groupby之后,如何访问print语句中的各个单元格。所有示例都显示了ipython的输出。我需要为其他软件格式化数据。我包含的代码不起作用。在
800200.2986 3859676.9971 WELL01 IZHA 107.000 10100.0000 6483.3506 6483.0552 -6376.0552 NIN
800200.2986 3859676.9971 WELL01 KEY B 107.000 10100.0000 6664.8892 6664.5864 -6557.5864 NIN
800200.2986 3859676.9971 WELL01 SIMS 107.000 10100.0000 2120.7332 2120.7112 -2013.7112 NIN2
800200.2986 3859676.9971 WELL01 BOT0 107.000 10100.0000 8426.7568 8426.3613 -8319.3613 NIN
800200.2986 3859676.9971 WELL01 BOT0-2A 107.000 10100.0000 8476.9834 8476.5830 -8369.5830 NIN
wls= pd.read_fwf(cmdl.datafilename,skiprows=10,colspecs= colwidths,names=colnames)
tpgrp = wls.groupby('Top')
tpgrpdict= dict(list(tpgrp))
tp0= tpgrp.get_group('BOT0')
#print tp0,tp0.count()
print tp0[['X','Y','TVDSS','Well']]
for t in tp0:
for i in range(len(t)):
print t[i],tp0[tp0[]['X']
您发布的数据帧没有名为“Top”的列,也没有名为“BOT0”的行。在
groupby()
返回一个DataFrameGroupBy对象,它有一个groups
属性,这是一个字典,其中组名是键,每个值是一个数组,其中包含该组的行的名称。您可以单步执行这些键并使用get_group()
将每个组名转换为一个数据帧。在然后,您可以使用
^{pr2}$.loc[]
访问单个细胞,例如:或者,您可以使用
.iloc[]
,例如:下面是一个例子:
相关问题 更多 >
编程相关推荐