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

desmond

I understand to create a dataframe, i need to specify index from my dictionary, else we get the 'ValueError: if using all scalar values, you must pass an index' error.

however, how do i create a dataframe from dictionary where the index is just an auto-increment number?

EdChum

You can construct an index using np.arange and pass the len of your dict:

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

However, if you only have a single value as scalar values in your dict then it's more appropriate to have a single row:

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

Out[165]:
   a  b
0  1  3

Or you can use from_dict and pass orient='index':

In [166]:
d = {'a':1,'b':3}
pd.DataFrame.from_dict(d, orient='index')

Out[166]:
   0
a  1
b  3

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

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

From Dev

Create a Dictionary from a Dataframe With the Index as the Keys

From Dev

How to create Alphanumeric Auto Increment

From Dev

How to increment Python Pandas DataFrame based on key/values from a dictionary

From Dev

Create a new list of dictionary from the index in dataframe Python with the fastest way

From Dev

Create field from auto increment value on INSERT

From Dev

How to create an auto increment primary key in SQLite

From Java

How to create id with AUTO_INCREMENT on Oracle?

From Dev

How to create second primary column ( Auto Increment)

From Dev

How to construct pandas DataFrame from dictionary with key as column and row index

From Dev

Create a DataFrame from a dictionary of DataFrames

From Java

How to create expanded pandas dataframe from a nested dictionary?

From Dev

How to create a dictionary of lists from two columns in a dataframe

From Dev

How to create dictionary of dictionaries from a dataframe using python's pandas

From Dev

How to implement inverted index from string list to dictionary using dict comprehension and auto-incremental id?

From Dev

How to get index of dictionary from an array of dictionary?

From Dev

how to instruct ecto to not create the auto increment id field?

From Dev

How to create Invoice Number in Text box and auto increment it on button click?

From Dev

How to create custom column with auto-increment characters

From Dev

How to create Invoice Number in Text box and auto increment it on button click?

From Java

How to convert dataframe to dictionary in pandas WITHOUT index

From Dev

How to convert dataframe to dictionary in pandas WITHOUT index

From Java

Problem of create Pandas Dataframe from dictionary

From Dev

create pandas dataframe from dictionary of dictionaries

From Dev

Create a nested dictionary from pd dataframe Python

From Dev

How to create a dictionary from slices of nested dictionary?

From Dev

How to create a sentence from a dictionary

From Dev

How to get recently inserted auto-increment id from mysql

From Dev

How to retrieve the auto increment field name from a table?

Related Related

  1. 1

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

  2. 2

    Create a Dictionary from a Dataframe With the Index as the Keys

  3. 3

    How to create Alphanumeric Auto Increment

  4. 4

    How to increment Python Pandas DataFrame based on key/values from a dictionary

  5. 5

    Create a new list of dictionary from the index in dataframe Python with the fastest way

  6. 6

    Create field from auto increment value on INSERT

  7. 7

    How to create an auto increment primary key in SQLite

  8. 8

    How to create id with AUTO_INCREMENT on Oracle?

  9. 9

    How to create second primary column ( Auto Increment)

  10. 10

    How to construct pandas DataFrame from dictionary with key as column and row index

  11. 11

    Create a DataFrame from a dictionary of DataFrames

  12. 12

    How to create expanded pandas dataframe from a nested dictionary?

  13. 13

    How to create a dictionary of lists from two columns in a dataframe

  14. 14

    How to create dictionary of dictionaries from a dataframe using python's pandas

  15. 15

    How to implement inverted index from string list to dictionary using dict comprehension and auto-incremental id?

  16. 16

    How to get index of dictionary from an array of dictionary?

  17. 17

    how to instruct ecto to not create the auto increment id field?

  18. 18

    How to create Invoice Number in Text box and auto increment it on button click?

  19. 19

    How to create custom column with auto-increment characters

  20. 20

    How to create Invoice Number in Text box and auto increment it on button click?

  21. 21

    How to convert dataframe to dictionary in pandas WITHOUT index

  22. 22

    How to convert dataframe to dictionary in pandas WITHOUT index

  23. 23

    Problem of create Pandas Dataframe from dictionary

  24. 24

    create pandas dataframe from dictionary of dictionaries

  25. 25

    Create a nested dictionary from pd dataframe Python

  26. 26

    How to create a dictionary from slices of nested dictionary?

  27. 27

    How to create a sentence from a dictionary

  28. 28

    How to get recently inserted auto-increment id from mysql

  29. 29

    How to retrieve the auto increment field name from a table?

HotTag

Archive