使用 pandas 版本 2,我在调用iteritems.
for event_id, region in column.iteritems():
pass
Run Code Online (Sandbox Code Playgroud)
出现以下错误消息:
Traceback (most recent call last):
File "/home/analyst/anaconda3/envs/outrigger_env/lib/python3.10/site-
packages/outrigger/io/gtf.py", line 185, in exon_bedfiles
for event_id, region in column.iteritems())
AttributeError: 'Series' object has no attribute 'iteritems'
Run Code Online (Sandbox Code Playgroud) 问题:运行以下代码时出现错误。我是新手,不知道如何解决这个问题。creae 函数将每个坐标点分配给它的自治市镇。
def find_borough(lat,lon):
"""
return the borough of a location given its latitude and longitude
lat: float, latitude
lon: float, longitude
"""
boro = 0 # initialize borough as 0
for k,v in boros.iteritems(): # update boro to the right key corresponding to the parent polygon
if v['polygon'].contains(Point(lon,lat)):
boro = k
break # break the loop once the borough is found
return [boro]
## Analyse the cluster now
# create data frame of boroughs
df = data1[data1.Trip_duration>=1350]
orig_dest = …Run Code Online (Sandbox Code Playgroud) 我正在尝试读取 YAML 文件并按照文件中的顺序打印出其中的列表。
所以 YAML:
b: ...
a: ...
Run Code Online (Sandbox Code Playgroud)
我的蟒蛇是:
for key, value in yaml.load(open(input_file)).items():
print(str(key))
Run Code Online (Sandbox Code Playgroud)
输出变为:
a
b
Run Code Online (Sandbox Code Playgroud)
但我需要它是b那时a。我也尝试过iteritems(),得到了同样的结果。
我正在尝试创建一个总结另一个的字典.我希望仅当密钥与details_dict中的"parent"值匹配时才会更新summary_dict.我所写的内容似乎并没有像我期望的那样访问summary_dict.print语句显示它继续追加循环中的第一个iterable,而不是从summary_dict中获取正确的值.
detail_dict = {'a123': {"data": [1, 2, 3, 4], "parent": "a"},
'a124': {"data": [1, 2, 3, 4, 5], "parent": "a"},
'b123': {"data": [1, 2, 3], "parent": "b"},
'b124': {"data": [1], "parent": "b"}}
summary_dict = dict.fromkeys(["a", "b"], {"data": [],
"data_len": []})
for k, v in detail_dict.iteritems():
summary_dict[v['parent']]["data"].append(v["data"])
summary_dict[v['parent']]["data_len"].append(len(v["data"]))
print "\nMy value is "
print v
print "\nMy summary dictionary now looks like:"
print summary_dict[v['parent']]
Run Code Online (Sandbox Code Playgroud)
我想要的结果字典是:
{"a": {"data": [[1, 2, 3, 4], [1, 2, 3, 4, 5]],
"data_len": [4, 5]},
"b": {"data": …Run Code Online (Sandbox Code Playgroud) 是否保证python 2.X的内置方法dict.items()并dict.iteritems()始终以相同的顺序返回项目?或者这些方法是非确定性的吗?
我的代码:
for column_name, column_data in summary_words.iteritems():
if column_name != "summary" and column_name != "text" and column_name != "score" and column_name != "helpfulness":
summary_words[column_name] = summary_words["summary"].str.count(column_name)
Run Code Online (Sandbox Code Playgroud)
其中summary_words是pandas数据框,“summary”是该数据框中的一列。当我运行代码时,我收到此错误:
AssertionError:管理器项目数必须等于块项目管理器项目的并集:6004,# tot_items:6005
有谁知道我为什么会收到此错误以及如何修复它?
great my This love you best and will favorite watch ... step succeeds judge (who strictly things, helpfulness score summary text
0 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN ... NaN NaN NaN NaN NaN NaN 100.0 3 "There Is So Much Darkness Now ~ Come For The …Run Code Online (Sandbox Code Playgroud) iteritems ×6
python ×6
dataframe ×2
dictionary ×2
pandas ×2
items ×1
json ×1
loops ×1
python-2.x ×1
python-3.x ×1
series ×1
yaml ×1