Ari*_*ris 3 python dictionary dataframe pandas
我有一本字典,比如:
dic = {'c': [14, 41],
'i': '52983542076720',
'p': 31.7,
's': 100,
't': 1611945588012261376,
'x': 11}
Run Code Online (Sandbox Code Playgroud)
我试过
pd.DataFrame(dic)
Run Code Online (Sandbox Code Playgroud)
和
pd.DataFrame.from_dict(dic,, orient='columns', dtype=int, columns=None)
Run Code Online (Sandbox Code Playgroud)
然而,它们都返回一个 2 行数据帧,例如:
| C | 我 | p | s | t | X | |
|---|---|---|---|---|---|---|
| 0 | 14 | 52983542076720 | 31 | 100 | 1611945588012261376 | 11 |
| 1 | 41 | 52983542076720 | 31 | 100 | 1611945588012261376 | 11 |
我实际上想得到一个像这样的数据框:
| C | 我 | p | s | t | X | |
|---|---|---|---|---|---|---|
| 0 | [14,41] | 52983542076720 | 31 | 100 | 1611945588012261376 | 11 |
知道我应该做什么才能得到结果吗?
您可以使用pandas.Series:
pd.Series(dic).to_frame().T
Run Code Online (Sandbox Code Playgroud)
输出:
c i p s t x
0 [14, 41] 52983542076720 31.7 100 1611945588012261376 11
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
562 次 |
| 最近记录: |