Home Creating a dataframe with append
Reply: 0

Creating a dataframe with append

user851
1#
user851 Published in May 21, 2018, 3:03 am

I'm trying to create a DataFrame with an append:

col_stats= ['Attribute', 'Mean', 'Var', 'Std']
stats = pd.DataFrame(columns=[col_stats])

for i in train:
    new_row = [
        i,
        train[i].mean(),
        np.var(train[i]),
        np.nanstd(train[i])
    ]
    new_row = pd.Series(new_row)
    stats = stats.append(new_row, ignore_index=True)

stats

It works when I eliminate this line:

    stats = stats.append(new_row, ignore_index=True)

If not, It gives me this error:

ValueError: Buffer dtype mismatch, expected 'Python object' but got 'long'

The 'Attribute' columns is a string (the name of the variable). The other columns (Mean, Var, Std) are numbers (integers, floats)

Why can I not use pd.df.append here?

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.310686 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO