0

I have a CSV file which looks like this

sr no;address;tempo;loudness

0;E:/project/song_directory/blues/Al Green - Lets Stay 
Together.mp3;95.703125;9.074317932128906

1;E:/project/song_directory/blues/Blackstreet - No Diggity ft. Dr. Dre 
Queen Pen.mp3;89.10290948275862;10.246162414550781

2;E:/project/song_directory/blues/Destiny's Child - Say My Name 
(Official Music Video).mp3;129.19921875;9.540428161621094

I want to extract the 2nd column from the file and then compare it with the variable 'songname_selected'.

import pandas as pd
import numpy as np
song = pd.read_table('E:/project/new.csv', sep=';')

song.address #  all the name
songname_selected =  'E:/project/song_directory/blues/Al Green - Lets 
Stay Together.mp3'
for row in song.address:   
    if row is songname_selected:
        print("true")
    else:
        print("false")

I expect the output to be true when the songname_selected matches with the value in the 2nd column. However, code would never return true.

Becky
  • 191
  • 1
  • 1
  • 10

1 Answers1

1

try

for row in song.address:   
    if row == songname_selected: ## don't use 'is' here
        print("true")
    else:
        print("false")

output

true
false
false

reason Is there a difference between β€œ==” and β€œis”?

Akhilesh_IN
  • 1,217
  • 1
  • 13
  • 19