hammies
hammies

Reputation: 1435

Unable to add Series to Dataframe using append

It keeps returning empty dataframe. Not very sure why. I also named my columns in df_group to match g_row. I also tried pd.concate. Still empty dataframe

df_group = pd.DataFrame()
added = []
for i, g_row in df.iterrows():
    if i not in added:
        print g_row #not empty; type(g_row) Series
        df_group.append(g_row, ignore_index=True)
        added.append(i)

print df_group #empty

Upvotes: 0

Views: 102

Answers (1)

Rishabh Srivastava
Rishabh Srivastava

Reputation: 917

append does not work inplace. This will work df_group = df_group.append(g_row, ignore_index=True).

Upvotes: 2

Related Questions