将每行 Pandas 数据帧写入一个新的文本文件 - pythonic 方式 [英] Write each row of pandas dataframe into a new text file - pythonic way

查看:50
本文介绍了将每行 Pandas 数据帧写入一个新的文本文件 - pythonic 方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果有一种方法可以逐行解析 Pandas 数据帧并将每一行的内容写入新的文本文件,我正在尝试使用谷歌搜索.我的数据框由一个名为 Reviews 的列组成.

I was trying to google up if there's a way to parse a pandas dataframe row wise and write the contents of each row into a new text file. My dataframe consists of a single column called Reviews.

我希望对电影评论进行一些情绪分析,并且我需要将每条评论放在一个单独的文本文件中.有人可以在这里帮助我.

I'm looking to do some sentiment analysis on movie reviews and that I need each review to be in a separate text file. Can somebody help me here.

推荐答案

我已经写过类似的东西并且它有效.无论如何感谢您的投入

I've written something like this and it works. anyways thanks for your inputs guys

for index, row in p.iterrows():
    if i > len(p):
       break
    else:
       f = open(str(i)+'.txt', 'w')
       f.write(row[0])
       f.close()
       i+=1

其中 p 是一个数据框.

where p is a dataframe.

这篇关于将每行 Pandas 数据帧写入一个新的文本文件 - pythonic 方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆