Jedi Schmedi
Jedi Schmedi

Reputation: 818

Appending values to empty dataframe returns NaN values

I want to append all shop dates to a new dataframe. But when I append it all values is NaN Im sure that sd has values, I've printed it and it was plenty. :)

cg = vn[vn['name'] == n]
data = pd.DataFrame(data=None, columns=cg.columns,index=cg.index)

for date in cg['date'].unique():
    sd = cg[(cg['date'] == date)]
    data.append(sd, ignore_index=True)

print(data)

Upvotes: 0

Views: 407

Answers (2)

ATL
ATL

Reputation: 591

I think it should be

data = data.append(sd, ignore_index=True)

append returns a dataframe, it's not in-place.

Upvotes: 1

Nullman
Nullman

Reputation: 4279

DataFrame.append doesn't not do what List.append does, it more closely resembles List + item in behavior.

It doesn't change your object but instead returns a new object with the item appended

here is the documentation for this

Upvotes: 1

Related Questions