python-3.x - AttributeError:“系列”对象没有属性“行”
问题描述
我希望我的程序在他识别一个字符串时打印前五个字符,该字符串由添加两列(来自用熊猫制作的数据框)组成,在 .txt 的某些行中,但正如标题中所说,它当我运行代码时给我这个错误。这是代码(重要的行在代码的末尾,如果您想查看整个代码,我只是把所有内容都放了)。
import pandas as pd
import re
import numpy as np
link = "excelfilett.txt"
file = open(link, "r")
frames_load = []
is_count_frames_load = False
for line in file:
if "[Interface1]" in line:
is_count_frames_load = True
if is_count_frames_load== True:
frames_load.append(line)
if "[EthernetComNeed]" in line:
break
number_of_rows_load = len(frames_load) -1
header_load = re.split(r'\t', frames_load[0])
number_of_columns_load = len(header_load)
frame_array_load = np.full((number_of_rows_load, number_of_columns_load), 0)
df_frame_array_load = pd.DataFrame(frame_array_load)
df_frame_array_load.columns= header_load
for row in range(number_of_rows_load):
frame_row_load = re.split(r'\t', frames_load[row])
for position in range(len(frame_row_load))
df_frame_array_load["[Name]"] = df_frame_array_load["[End1]"] + " " + df_frame_array_load["[End2]"]
link = "excelfilett.txt"
file = open(link, "r")
frames_path = []
is_count_frames_path = False
for line in file:
if "[Routing Paths]" in line:
is_count_frames_path = True
if is_count_frames_path== True:
for row in df_frame_array_load["[Name]"].rows:
if row in line:
print(line[0:4])
if "[EthernetComConfig]" in line:
break
它给了我关于“df_frame_array_load [“[Name]”].rows:”中的行的AttributeError,它不应该是版本错误,那么问题是什么?我不明白。
解决方案
for row in df_frame_array_load["[Name]"].rows:
因为 pandas Series 对象没有“rows”属性,因为您在Series
迭代它时执行循环操作。
应该改为:
for row in df_frame_array_load["[Name]"]:
...
推荐阅读
- c++ - 检查 std::list 迭代器是否结束而无法访问容器
- angular - 使用带有编码数据的 window.open() 时出现 Angular HTTP 错误 431
- sql-server - 计算与多个父级的父子关系的分数
- python - 带有 json 数组的 Postgres/SqlAlchemy 选择记录包含来自另一个 json 数组的至少 1 个 json
- javascript - Javascript 没有调用子例程
- html - 根据类及其 href 内容设置链接样式
- vue.js - 捆绑 Vue3 组件库以在 Vue2 应用程序中工作
- vue.js - Vuex状态重置功能未定义
- python - Pandas 基于时间的平均值
- python - 如何使用 Python 处理 XML 标记数组以获取每个对象?