Python error: Incompatible Indexer with Series

pandas
python

#1

Hi,

I’m trying to assign a value to a dataframe cell using the following commands:

feature_summary = pd.DataFrame(index=range(shape_train[1]),columns=["Feature","Type","#unique(Train)","#unique(Test)"])

    for i in summary_train_categorical.index:
        feature_summary.loc[i,"Feature"] = summary_train_categorical.loc[i,"Feature"]
        feature_summary.loc[i,"Type"] = "Categorical"
        feature_summary.loc[i,"#unique(Train)"] = summary_train_categorical.loc[i,"#unique_values"]
        feature_summary.loc[i,"#unique(Test)"] = summary_test_categorical.loc[summary_test_categorical["Feature"]==summary_train_categorical.loc[i,"Feature"],"#unique_values"]
        i+=1
    numcat = shape_train_categorical[1]

The error is appearing in the line:
feature_summary.loc[i,"#unique(Test)"] = summary_test_categorical.loc[summary_test_categorical["Feature"]==summary_train_categorical.loc[i,"Feature"],"#unique_values"]

Here summary_train_categorical & summary_test_categorical are dataframes containing the columns used in the above code.

A series is being returned by “summary_test_categorical[“Feature”]” but I’m not using any indexing there. Just a simple comparison.

Please help me debug the issue.

Thanks,
Aarshay