以下のような形式のファイルを読み込もうとしています。各行の間に2つの '\ n'スペースがあります。私は2つを使用しているのでPython:2行の空白があるファイルから行を読み取る方法
0 I was very inspired by Louise's Hay approach t...
1 \n You Can Heal Your Life by
2 \n I had an older version
3 \n I love Louise Hay and
4 \n I thought the book was exellent
:
open_reviews = open("C:\\Downloads\\review_short.txt","r",encoding="Latin-1").read()
documents = []
for r in open_reviews.split('\n\n'):
documents.append(r)
df = pd.DataFrame(documents)
print(df.head())
私は取得しています出力は以下の通りです:
Great tool for healing your life--if you are ready to change your beliefs!<br /><a href="http
Bought this book for a friend. I read it years ago and it is one of those books you keep forever. Love it!
I read this book many years ago and have heard Louise Hay speak a couple of times. It is a valuable read...
私はラインを読み、データフレームに変換するPythonコードの下に使用しています(\ n)、各行の先頭に追加されます。これを処理する方法は他にありますので、次のように出力します:
0 I was very inspired by Louise's Hay approach t...
1 You Can Heal Your Life by
2 I had an older version
3 I love Louise Hay and
4 I thought the book was exellent
ありがとうございます。それはうまくいった。 –