python-3.x - 将数据转换为 CSV 文件
问题描述
我正在引入 json.dumps 的数据以通过 MQTT 代理。在我做一个 json.loads 之后,我得到了这些数据作为回报。
[['date here', '1713180'], ['date here', '1713181'], ['date here', '1713182'], ['date here', '1713183'], ['date here', '1713184']]
我在 csv 写入方面尝试了许多其他线程,但我完全不知道如何将其正确写入 CSV。
解决方案
“你可以使用熊猫:
如果您没有安装 pandas,请运行以下命令来安装它:
pip install pandas
然后,您可以使用:
import pandas as pd
data = [['date here', '1713180'], ['date here', '1713181'], ['date here', '1713182'], ['date here', '1713183'], ['date here', '1713184']]
df = pd.DataFrame(data)
df.to_csv("path/to/file.csv")
推荐阅读
- java - 在查询的任何表中都找不到列(名称)(或 SLV 未定义)
- c++ - CLion 没有调试我的目标之一 - 立即“进程以退出代码 0 完成”
- javascript - 基于数组的 jQuery 选择选项在 Safari 中不起作用
- vba - VBA - 具有命名范围内的值的组合框
- python - 在字符上拆分字符串,除非转义
- python - Python 的 __slots__ 和数据类的(内存方面和访问时间方面)比较是什么
- amazon-web-services - VPC 设置将 Elastic Beanstalk URL 的访问限制为仅 API 网关?
- c# - 画很多线很慢
- java - 根据在不同列中测试的条件创建具有组标签的新列
- php - 您可以扫描目录以查找某个值(例如 20.jpg-40.jpg)之间的文件名吗?PHP