创建数据框时出错 "pandas.errors.InvalidIndexError"

Error "pandas.errors.InvalidIndexError" while Creating Dataframe

我正在尝试在迭代时从另一个 Dataframe 的行创建一个 Dataframe。下面是我的代码:

df_cols = ["categoryname", "issueid", "module", "type", "description", "sourcefile", "line", "description"]

mydataframe = pd.DataFrame()
for index, row in nw.iterrows():
    if (row['issueid'] in nw1['issueid'].values):
        print(str(row['issueid']) + "is present")
    else:
        print(str(row['issueid']) + " is not present")
        # mydataframe=mydataframe.append(row, ignore_index=True)
        new_df = pd.DataFrame([row], columns=df_cols)          #ERROR
        #mydataframe = pd.concat([mydataframe, new_df], axis=0, ignore_index=True)

对于行:

  new_df = pd.DataFrame([row], columns=df_cols)

我遇到错误:

 pandas.errors.InvalidIndexError: Reindexing only valid with uniquely valued Index objects

通过将元组“行”转换为列表并将其作为参数传递给 Dataframe 解决,如下所示:

df_cols = ["categoryname", "issueid", "module", "type", "description", "sourcefile", "line", "description"]

mydataframe = pd.DataFrame()
for index, row in nw.iterrows():
    if (row['issueid'] in nw1['issueid'].values):
        print(str(row['issueid']) + "is present")
    else:
        print(str(row['issueid']) + " is not present")
        # mydataframe=mydataframe.append(row, ignore_index=True)
        new_df = pd.DataFrame([list(row)], columns=df_cols)          #Works Now
        #mydataframe = pd.concat([mydataframe, new_df], axis=0, ignore_index=True)