0

My code is throwing this error when I try to run it, and I don't understand why. I'm confused as to why it's throwing an AttributeError when the line clearly calls .explode(...) as a function. Any help would be appreciated.

Error:

Traceback (most recent call last):
  File "train_transformer_v5.py", line 782, in <module>
    main()
  File "train_transformer_v5.py", line 763, in main
    global_step, tr_loss, metrics_result = trainer.train(args)
  File "train_transformer_v5.py", line 451, in train
    tb_writer=self.tb_writer, global_step=self.global_step)
  File "/home/xianx/model/metrics_v5.py", line 596, in eval_metrics
    qps[thr] = metrics_calculator.map_and_compute_qp(pri_nodes[thr], node_mappings, primary_gt_data_path, args)
  File "/home/xianx/model/metrics_v5.py", line 353, in map_and_compute_qp
    qpv2 = self.compute_qp(pred_df, gt_data_path)
  File "/home/xianx/model/metrics_v5.py", line 358, in compute_qp
    pred_df = pred_df.explode('TextNodeId')
  File "/opt/conda/lib/python3.6/site-packages/pandas/core/generic.py", line 5067, in __getattr__
    return object.__getattribute__(self, name)
AttributeError: 'DataFrame' object has no attribute 'explode'

Version Info:

$ pip install pandas
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: pandas in /opt/conda/lib/python3.6/site-packages (0.24.2)
Requirement already satisfied: pytz>=2011k in /opt/conda/lib/python3.6/site-packages (from pandas) (2020.1)
Requirement already satisfied: python-dateutil>=2.5.0 in /opt/conda/lib/python3.6/site-packages (from pandas) (2.8.1)
Requirement already satisfied: numpy>=1.12.0 in /opt/conda/lib/python3.6/site-packages (from pandas) (1.19.1)
Requirement already satisfied: six>=1.5 in /opt/conda/lib/python3.6/site-packages (from python-dateutil>=2.5.0->pandas) (1.15.0)

Code:

def compute_qp(self, pred_df, gt_data_path):
        pred_df = pred_df.explode('TextNodeId')
        ...
wheeeee
  • 1,046
  • 2
  • 14
  • 33
  • Is 'TextNodeId' a column in your dataframe? – le_camerone Aug 25 '22 at 02:09
  • 1
    I think issue is your pandas version. Check this documentation fpr 0.24.2, cant find explode function https://pandas.pydata.org/pandas-docs/version/0.24/reference/frame.html. Check this answer for alternate options, https://stackoverflow.com/questions/53218931/how-to-unnest-explode-a-column-in-a-pandas-dataframe-into-multiple-rows – Abhishek Aug 25 '22 at 02:35
  • You can always trying upgrading your pandas version: `pip install -U pandas` – BeRT2me Aug 25 '22 at 02:42

0 Answers0