Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 如何在python中使多行文本文件成为数据帧?_Python 3.x_Dataframe_Nlp - Fatal编程技术网

Python 3.x 如何在python中使多行文本文件成为数据帧?

Python 3.x 如何在python中使多行文本文件成为数据帧?,python-3.x,dataframe,nlp,Python 3.x,Dataframe,Nlp,有混乱的文本文件,需要将其转换为csv文件格式,如何实现,例如: 你好,这是第一线。 这是两条线都是一条原始线 你好,这是第二线。 这是两条线都是一条原始线 如何将多行文本(如段落)转换为数据框或cv格式您可以先读取行,然后将列表传递到数据框: 示例文件: sample.txt: hello this is first line. this is both lines are one raw. hello this is second line. this is both lines are o

有混乱的文本文件,需要将其转换为csv文件格式,如何实现,例如:

你好,这是第一线。 这是两条线都是一条原始线

你好,这是第二线。 这是两条线都是一条原始线


如何将多行文本(如段落)转换为数据框或cv格式您可以先读取行,然后将列表传递到数据框:

示例文件:
sample.txt

hello this is first line. this is both lines are one raw.
hello this is second line. this is both lines are one raw.
代码:
将熊猫作为pd导入
#阅读这些行并创建一个数据帧
以open(“/content/sample.txt”,“r”)作为文件句柄:
df=pd.DataFrame(文件\u handle.readlines())
#将数据帧保存到CSV
df.to_csv(“output/file.csv”)