import pandas
df = pandas.read_csv("myfile.csv", header=None)
file_to_write = ""
for index in df.index:
df.loc[index].to_json("row{}.json".format(index))
with open("row{}.json".format(index)) as file_handle:
file_content = file_handle.read()
file_to_write += file_content + "\n"
with open("result.jsonl","w") as file_handle:
file_handle.write(file_to_write)
我不确定这个结果是否符合“jsonl”语法,但这是一个可能会导致相关结果的黑客行为
主要技巧是在导出时将输入文件的每一行视为单独的JSON文件,然后从磁盘读回JSON并将其视为不同的jsonl行
我从一个包含
下面的代码段基于another post
生成的.jsonl文件包含
如果不需要行索引,可以从上面Python代码段的.to_json()行中删除这些索引
相关问题 更多 >
编程相关推荐