我有一个看起来像这样的CSV文件
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
我想从文件中提取第二列,然后将其与变量“ 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")
我期望当songname_selected与第二列中的值匹配时输出为true。但是,代码永远不会返回true。
答案 0 :(得分:1)
尝试
for row in song.address:
if row == songname_selected: ## don't use 'is' here
print("true")
else:
print("false")
输出
true
false
false