-1

I am trying to read data from csv and compare value from ‘Sentiment’ column against

df1 = pd.read_csv('C:\\Python\\hack\\customer_reviews_further_analysis3.csv')
df2 = pd.read_csv('C:\\Python\\hack\\Bank_Offers_data.csv')

cols = ['CustomerRating','CustomerFeedback', 'Sentiment','Bank','Card','TravelnHotel','Rewards','Lifestyle','Charge']

quotes=[]

if ((df1.Sentiment == 1) | (df1.Sentiment == 4)):
    if((df1.CustomerRating == 5) | (df1.CustomerRating == 4)):
        while((df1.TravelnHotel == df2.TravelnHotel) & (df1.Rewards == df2.Rewards) & (df1.Lifestyle == df2.Lifestyle) & (df1.Charge == df2.Charge)):
            continue
        quotes.append(df1['Sentiment','Bank','Card','TravelnHotel','Rewards','Lifestyle','Charge'])
        
Error:
runfile('C:/Python/ProductComparison_10Dec.py', wdir='C:/Python')
Traceback (most recent call last):

  File "C:\Python\ProductComparison_10Dec.py", line 29, in <module>
    if ((df1.Sentiment == 1) | (df1.Sentiment == 4)):

  File "C:\Users\176226\Anaconda3\lib\site-packages\pandas\core\generic.py", line 1479, in __nonzero__
    f"The truth value of a {type(self).__name__} is ambiguous. "

ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().

Referred previous solution on: Truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all() However this did not help

deceze
  • 510,633
  • 85
  • 743
  • 889
unlockAIML
  • 13
  • 1

1 Answers1

0

First the error comes from your while line. You again compare lists with each other. It is not completely clear what you are trying to implement there. Does there have to be at least one element from the first dataframe and that specific column to be existent in the same column of the second dataframe or do they have to be exactly the same. I assume that you are trying to implement something similar to a join function function from sql where one element has to existent in the other set.

Could you clarify that?

Maybe this is what you wanted:

if (1 in df1.Sentiment or 4 in df1.Sentiment):
    if (5 in df1.CustomerRating or 4 in df1.CustomerRating ):
        while (any(x in df2.TravelnHotel for x in df1.TravelnHotel)
                & any(x in df2.Rewards for x in df1.Rewards)
                & any(x in df2.Lifestyle for x in df1.Lifestyle)
                & any(x in df2.Charge for x in df1.Charge)):
            continue
            quotes.append(df1['Sentiment', 
                              'Bank', 
                              'Card', 
                              'TravelnHotel', 
                              'Rewards', 
                              'Lifestyle', 
                              'Charge'])
  • Thank You! the if conditions are working as expected :) . whereas while loop and append is not working. The while loop is to check if df1.xparameter == df2.xparameter matched then ignore else add those values in another csv using quotes.append(df1....) – unlockAIML Dec 12 '20 at 05:07