0
我想將python dict
轉換爲pandas dataframe
。列的數量應該等於特定鍵值的數量。從下面的例子中,列名應爲i
,a
,b
,c
,並d
其中i
是字典鍵,其餘的都是值:如何將具有多個值的字典轉換爲熊貓數據框?
e = {}
for i in range(0,len(length_of_the_row)):
e[i] = a,b,c,d
我想將python dict
轉換爲pandas dataframe
。列的數量應該等於特定鍵值的數量。從下面的例子中,列名應爲i
,a
,b
,c
,並d
其中i
是字典鍵,其餘的都是值:如何將具有多個值的字典轉換爲熊貓數據框?
e = {}
for i in range(0,len(length_of_the_row)):
e[i] = a,b,c,d
嘗試.from_dict()
:
import pandas as pd
e = {}
for i in range(0, len("length_of_the_row")):
e[i] = "a", "b", "c", "d"
df = pd.DataFrame.from_dict(e, orient='index')
把字典直接變成dataframe
,然後轉置它,因爲行和列需要交換:
import pandas as pd
e_df = pd.DataFrame(e)
e_df = e_df.T