【发布时间】:2020-06-10 14:57:34
【问题描述】:
我正在使用 Kaggle Spotify 1921-2020 (data.csv) 数据集,其中包含 object 数据类型的列“艺术家”,我尝试对数据框 spotify[spotify['artists'] == 'Dennis Day'] 执行条件提取,它不输出任何行无论我输入什么值都会发生。我试图将其数据类型更改为strspotify.artists.apply(str),但仍然没有发生任何事情,它的数据类型仍然显示为object
到目前为止我做了什么
# previously the value was like
0 ['Dennis Day']
1 ['Sergei Rachmaninoff', 'James Levine', 'Berli...
# I remove the square braces
spotify['artists'] = spotify['artists'].apply(lambda x : x[1:-1])
0 'Dennis Day'
1 'Sergei Rachmaninoff', 'James Levine', 'Berlin...
# since it was giving no output for any value I checked this
for i in songs.artists.head(10):
print(f'{i} is present {i in songs.artists}')
# and see what I get
'Dennis Day' is present False
'Sergei Rachmaninoff', 'James Levine', 'Berliner Philharmoniker' is present False
'John McCormack' is present False
# don't get confused if somewhere it is written songs and instead of spotify they are same.
我尝试将 Kaggle notebook 更改为 jupyterlab,但它都一样,所以我现在该怎么办
【问题讨论】:
-
"'Dennis Day'"怎么样? -
在我看来,字符串中包含单个刻度。
-
还是一样的结果@Kris
-
这能回答你的问题吗? Using in operator with Pandas series
标签: python-3.x pandas