我正在尝试使用 pandas 清理数据。当我执行 df.datatypes 时,它显示列是对象类型。我希望将它们转换为数字类型。我尝试了各种方法来这样做;
data[['a','b']] = data[['a','b']].apply(pd.to_numeric, errors ='ignore')
Run Code Online (Sandbox Code Playgroud)
然后,
data['c'] = data['c'].infer_objects()
Run Code Online (Sandbox Code Playgroud)
但似乎没有任何效果。解释器不会抛出任何错误,但同时不会执行所需的转换。
任何帮助将不胜感激。
提前致谢。
我希望抓取以下网址中显示的所有图像: happiness
我尝试了很多方法,但只能获取 20 张图像。下面是相同的 Python 代码:
query = input("happiness")# you can change the query for the image here
image_type="ActiOn"
query= query.split()
query='+'.join(query)
url="https://www.google.co.in/search?q="+query+"&source=lnms&tbm=isch"
print(url)
#add the directory for your image here
DIR="Pictures"
header={'User-Agent':"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36
(KHTML, like Gecko) Chrome/43.0.2357.134 Safari/537.36"
}
soup = get_soup(url,header)
if not os.path.exists(DIR):
os.mkdir(DIR)
DIR = os.path.join(DIR, query.split()[0])
if not os.path.exists(DIR):
os.mkdir(DIR)
images = [a['src'] for a in soup.find_all("img", {"src":
re.compile("gstatic.com")})]
print(images)
print("there are total" , len(images),"images")
image_type = "Action"
#print images …Run Code Online (Sandbox Code Playgroud)