首页 > 解决方案 > 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,它不应该是版本错误,那么问题是什么?我不明白。

标签: python-3.xpandasdataframe

解决方案


for row in df_frame_array_load["[Name]"].rows:

因为 pandas Series 对象没有“rows”属性,因为您在Series迭代它时执行循环操作。

应该改为:

for row in df_frame_array_load["[Name]"]:
    ...

推荐阅读