作为SEO管理人员,我使用这个python代码来查看H1标记在不同网页的桌面版和移动版上是否相同:
##Print the path of your current working directory
import os
print(os.getcwd())
#What you get here is where you should save your CSV crawls
##Import Panda Library
import pandas as pd
import numpy
##Load the crawls to Pandas
dfTextonly = pd.DataFrame(pd.read_csv('mobile.csv', low_memory=False, header=0))
dfTextonly = dfTextonly[['Address', 'H1-1']].copy()
dfJS = pd.DataFrame(pd.read_csv('desktop.csv', low_memory=False, header=0))
dfJS = dfJS[['Address','H1-1']].copy()
#Combine the two crawls into one dataframe
df = pd.merge(dfTextonly, dfJS, left_on='Address', right_on='Address', how='outer')
##Check the differences
df["H1s are equal"] = numpy.where((df["H1-1_y"] == df["H1-1_x"]), "yes", "no")
##Export in Excel
df.to_excel("test-results.xlsx")但是,问题是,当H1-1_y和H1-1_x都是"nan“(空字符串)时,此代码中的numpy.where返回"no”值,而它应该返回"yes“,因为在这种情况下,它们是相同的。有人能帮我吗?
样本数据
发布于 2022-01-27 15:02:19
如果是像你在评论中提到的那样处理NaN == NaN的话,你可以使用熊猫。代码看上去有点麻烦,所以您可以决定是否需要,但是可以尝试。
df["H1s are equal"] = pd.Series(["yes"]*len(df["H1-1_y"])).where(df["H1-1_y"]==df["H1-1_x"], "No")https://stackoverflow.com/questions/70879440
复制相似问题