python - 如何从字典创建熊猫数据框并将列表保存在一个单元格中
问题描述
我有一本像这样的字典:
dic = {'c': [14, 41],
'i': '52983542076720',
'p': 31.7,
's': 100,
't': 1611945588012261376,
'x': 11}
我试过了
pd.DataFrame(dic)
和
pd.DataFrame.from_dict(dic,, orient='columns', dtype=int, columns=None)
但是,它们都返回一个 2 行数据框,例如:
C | 一世 | p | s | 吨 | X | |
---|---|---|---|---|---|---|
0 | 14 | 52983542076720 | 31 | 100 | 1611945588012261376 | 11 |
1 | 41 | 52983542076720 | 31 | 100 | 1611945588012261376 | 11 |
我实际上想得到一个像这样的数据框:
C | 一世 | p | s | 吨 | X | |
---|---|---|---|---|---|---|
0 | [14,41] | 52983542076720 | 31 | 100 | 1611945588012261376 | 11 |
关于我应该怎么做才能得到结果的任何想法?
解决方案
您可以pandas.Series
改用:
pd.Series(dic).to_frame().T
输出:
c i p s t x
0 [14, 41] 52983542076720 31.7 100 1611945588012261376 11
推荐阅读
- azure - Azure Function BlobContainer.ListBlob 在 Portal CScript 中可用,在 VS C# 中不可用
- image - Android 和 iOS 之间的 Xamarin Forms 图像不匹配
- sql - 在 2 列的条件下从 sql server 中删除重复值
- amazon-web-services - Spark - “spark.deploy.spreadOut = false”可以在 S3 上提供性能优势
- python - 加快熊猫循环计数器
- html - FireFox 中的 SVG 渲染不准确
- macos - 更改输入设备后 AudioKit 导出异步失败
- opencv - 获取已在 OpenCV C++ 中的跟踪算法中跟踪的 ROI 的 x 和 y 像素坐标
- html - Bootstrap 4 - 在css中通过根名称引用颜色
- java - 如何使spring REST api消费者