Reputation: 2187
With class definition of:
import pandas as pd
class ScoreDataManager:
def __init__(self):
self.frameColumns = ['Reference', 'Translation', 'METEOR', 'TER', 'BLEU']
self._df = pd.DataFrame(columns=self.frameColumns)
def add_row(self, ref, trans, meteor, ter, bleu):
self._df.append({'Reference': ref, 'Translation': trans, 'METEOR': meteor, 'TER': ter, 'BLEU': bleu},
ignore_index=True)
def show(self):
print(self._df.head())
If I run:
x = ScoreDataManager()
x.add_row('abc', 'abcd', 0.9, 0.87, 0.901)
x.show()
I get:
Empty DataFrame
Columns: [Reference, Translation, METEOR, TER, BLEU]
Index: []
But I expect the dataframe to contain the appended row.
Upvotes: 0
Views: 129
Reputation:
Unlike normal append()
, the append()
is not in-place. You have to store the output.
def add_row(self, ref, trans, meteor, ter, bleu):
self._df=self._df.append({'Reference': ref, 'Translation': trans, 'METEOR': meteor, 'TER': ter, 'BLEU': bleu},
ignore_index=True)
Upvotes: 1