pandas - How to create a dataframe from dictionary with auto-increment index -


i understand create dataframe, need specify index dictionary, else 'valueerror: if using scalar values, must pass index' error.

however, how create dataframe dictionary index auto-increment number?

you can construct index using np.arange , pass len of dict:

pd.dataframe(your_dict, index = np.arange(len(your_dict))) 

however, if have single value scalar values in dict it's more appropriate have single row:

in [165]: d = {'a':1,'b':3} pd.dataframe(d, index=[0])  out[165]:     b 0  1  3 

or can use from_dict , pass orient='index':

in [166]: d = {'a':1,'b':3} pd.dataframe.from_dict(d, orient='index')  out[166]:    0  1 b  3 

Comments

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -