Giter VIP home page Giter VIP logo

customer-reviews-sentiment-analysis's Introduction

Sentiment Analysis of Customer Reviews

This code is used to perform sentiment analysis on a dataset of customer reviews. It uses the SentimentIntensityAnalyzer function from the nltk library to analyze the sentiment of the text in the text column of the df dataframe. The function returns a dictionary of scores for different sentiments (positive, negative, neutral), with the compound score representing the overall sentiment of the text. The compound_score column is created by extracting the compound score from the dictionary, and the positive_negative column is created by applying a lambda function to the compound_score column that assigns the value "Positive" if the compound score is greater than 0 and "Negative" otherwise. The number of positive and negative reviews is then counted using the value_counts function. Finally, a new dataframe positive_data is created by filtering the original dataframe to only include rows with the value "Positive" in the positive_negative column.

Getting Started

These instructions will guide you through the process of running this code on your local machine.

Prerequisites

You will need to have the following libraries installed:

pandas
nltk

You can install these libraries by running the following command:

pip install pandas nltk

Running the code

  1. Download the customer_reviews.csv file and place it in a directory on your local machine.
  2. Open the sentiment_analysis.py file and update the file path for the customer_reviews.csv file to the correct file path on your machine.
  3. Run the sentiment_analysis.py file.

How the code works

  1. The customer_reviews.csv file is loaded into a pandas dataframe.
  2. The nltk library is imported and the vader_lexicon is downloaded.
  3. The SentimentIntensityAnalyzer function from nltk is called to perform sentiment analysis on the review text.
  4. A new column called "score" is added to the dataframe, which contains the sentiment scores for each review.
  5. A new column called "compound_score" is added to the dataframe, which extracts the compound score from the "score" column.
  6. A new column called "positive_negative" is added to the dataframe, which categorizes the review as positive or negative based on the compound score.
  7. The value_counts function is used to count the number of positive and negative reviews.
  8. A new dataframe called "positive_data" is created, which contains only the positive reviews.

Results

The code will output the following:

The sentiment scores for the first review in the dataframe
The updated dataframe with the "score", "compound_score", and "positive_negative" columns
The count of positive and negative reviews
The dataframe containing only the positive reviews.

customer-reviews-sentiment-analysis's People

Contributors

arienox avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.