我们如何将数据框的值与序列进行比较?
我想找到一本销量最高的书。为此,我创建了一个包含所有书籍名称的系列(unique_books)。接下来,我想将其值与书籍列(书籍名称)进行比较,但它不断生成错误。我是一个新手,所以这个问题对你来说可能感觉很愚蠢。请原谅我的愚蠢并帮助我解决这个问题。任何帮助将不胜感激。
unique_books = pd.Series(unique_books) #converting ndarray to pd series
type(unique_books)
bestselling = pd.Series(unique_books, dtype="int")
type(bestselling)
counter = 0
bestselling_book = 0
for i in range(0, len(df['Book Name'])):
if df[df["Book Name"]].equals(unique_books[unique_books[i]]):
counter += 1
if bestselling_book < counter:
bestselling_book = counter
print ("The best selling book is " + str(bestselling_book))
I want to find a book with most sold score. For this, I have created a series (unique_books) with names of all the books. Next, I want to compare its values with the books column (Book Name) but it is keep generating errors. I an a newbie so this question may feel dumb to you. Please excuse my silliness and do help me sort it out. Any help would be appreciated.
unique_books = pd.Series(unique_books) #converting ndarray to pd series
type(unique_books)
bestselling = pd.Series(unique_books, dtype="int")
type(bestselling)
counter = 0
bestselling_book = 0
for i in range(0, len(df['Book Name'])):
if df[df["Book Name"]].equals(unique_books[unique_books[i]]):
counter += 1
if bestselling_book < counter:
bestselling_book = counter
print ("The best selling book is " + str(bestselling_book))
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据您的评论:
输出:
Based on your comment:
output: