简体   繁体   中英

How do I convert these 2 columns as seen below in In [10] to a dataframe/table to be able to export to a csv file

enter image description here

Hi, I am very new to Python and I plan to create a final exportable table with these reviews scraped from a website to see the words that were most used. I have thus managed to get this 2 columns but have no idea how to proceed, can I directly export this into a table in excel or must I convert it into a dataframe then export it to a CSV? And what is the required code to run as such? Thank you so much for your help!!

It's convenient to use pandas library for working with dataframes:

import pandas as pd

series = pd.Series(wordcount)
series.to_csv("wordcount.csv")

However, if you use the code above, you'll get a warning. To fix it, there are 2 ways:

1) Add header parameter:

series.to_csv("wordcount.csv", header=True)

2) Or convert series to dataframe and then save it (without new index):

df = series.reset_index()
df.to_csv("wordcount.csv", index=False)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM