我正在尝试使用R中的readLines()函数读取url的html内容.但是,我收到一条"incomplete final line found"警告消息,如下所示?在这种情况下如何跳过最后一行?任何建议将非常感谢.
x <- readLines("https://in.finance.yahoo.com/industries/technology")
Warning message:
In readLines("https://in.finance.yahoo.com/industries/technology") :
incomplete final line found on 'https://in.finance.yahoo.com/industries/technology'
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用htmlTable包将数据帧转换为 html 表,然后RDCOMClient通过附加 html 表作为电子邮件正文,使用 Microsoft Outlook 作为使用包的电子邮件客户端发送电子邮件。我是 HTML 编码的新手,所以我不太熟悉如何使用 HTML 标签格式化表格。下面是我正在尝试做的一个例子。
# Library to send email from Microsoft Outlook
library(RDCOMClient)
# Library to create HTML table
library(htmlTable)
# Reading data from inbuilt 'mtcars' dataset
x <- head(mtcars)
# Create HTML table
y <- htmlTable(x,
rnames = FALSE,
caption="This is from htmlTable package",
align = paste(rep("c", ncol(x)), collapse = "|"),
align.header = paste(rep("c", ncol(x)), collapse = "|"))
# add the table as body of the email …Run Code Online (Sandbox Code Playgroud) 我正在开发一个 Python 程序,该程序将分发给我们的客户。
他们的要求是程序应该在没有他们手动干预的情况下处理一切。
如何在执行代码时检查并安装Python中缺少的模块?在 R 中,我可以使用下面提供的代码。
如何在 Python 中复制类似的东西?
# Check and install missing packages in R
list.of.packages <- c("RDCOMClient", "htmlTable")
new.packages <- list.of.packages[!(list.of.packages %in% installed.packages()[,"Package"])]
if(length(new.packages) > 0) {
install.packages(new.packages)
}
Run Code Online (Sandbox Code Playgroud) 我有一个数据框,如下所示。然后我将数据框转换为 html 表。
# Use RDCOMClient to send email from outlook
library(RDCOMClient)
# Use xtable to convert dataframe into html table
library(xtable)
# Create dataframe
df <- as.data.frame(mtcars[1:3,1:3])
# Create HTML object
df_html <- xtable(df)
Run Code Online (Sandbox Code Playgroud)
现在,我正在使用电子邮件线程通过 Outlook 在 R 中发送电子邮件中给出的绝妙解决方案从 Outlook发送电子邮件
## init com api
OutApp <- COMCreate("Outlook.Application")
## create an email
outMail = OutApp$CreateItem(0)
## configure email parameter
outMail[["To"]] = "dest@dest.com"
outMail[["subject"]] = "some subject"
outMail[["body"]] = df_html
## send it
outMail$Send()
Run Code Online (Sandbox Code Playgroud)
对于我的电子邮件正文,我想要我想作为 html 表附加的数据框 df。当我执行上述代码时,我收到以下错误消息。 …
我有下面的HTML代码。
<div align="center">
<input type="file" name="filePath"><br>
<input type="Submit" value="Upload File"><br>
</div>
Run Code Online (Sandbox Code Playgroud)
我正在尝试使用Selenium和Python查找两个元素“文件”和“提交”。以下是我尝试使用的代码。
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
# create a new Firefox session
driver = webdriver.Chrome()
# Maximize the browser window
driver.maximize_window()
# Enter the url to load
driver.get("<<MY PAGE TO LOAD>>")
# Wait for the page to load
driver.implicitly_wait(5)
# find the upload file type and pass a test value
upload_field = driver.find_element_by_partial_link_text('file')
upload_field.clear()
upload_field.send_keys("test")
Run Code Online (Sandbox Code Playgroud)
运行此代码时,我可以在Chrome浏览器中成功加载页面,但出现以下异常。
# Exception when trying to get element by type
Traceback …Run Code Online (Sandbox Code Playgroud) python selenium python-3.x selenium-chromedriver selenium-webdriver
我正在尝试在R中压缩多个CSV文件。以下是供参考的代码。
# Create two dataframes using inbuilt datasets for reproducible code
df1 <- head(mtcars)
df2 <- head(iris)
# Write the files as CSV into working directory
write.csv(df1, file = "Test_File1.csv", row.names = FALSE, quote = FALSE)
write.csv(df2, file = "Test_File2.csv", row.names = FALSE, quote = FALSE)
# Read the 2 CSV file names from working directory
Zip_Files <- list.files(path = getwd(), pattern = ".csv$")
# Zip the files and place the zipped file in working directory
zip(zipfile = "TestZip", files …Run Code Online (Sandbox Code Playgroud) 我是机器学习和Python的新手.我正在尝试在UCI存储库中的一个数据集上构建随机森林回归模型.这是我的第一个ML模型.我的方法可能完全错了.
数据集可在此处获取 - https://archive.ics.uci.edu/ml/datasets/abalone
下面是我编写的整个工作代码.我在Windows 7 x64操作系统上使用Python 3.6.4(请原谅我冗长的代码).
import tkinter as tk # Required for enabling GUI options
from tkinter import messagebox # Required for pop-up window
from tkinter import filedialog # Required for getting full path of file
import pandas as pd # Required for data handling
from sklearn.model_selection import train_test_split # Required for splitting data into training and test set
from sklearn.ensemble import RandomForestRegressor # Required to build random forest
#------------------------------------------------------------------------------------------------------------------------#
# Create an instance of tkinter and …Run Code Online (Sandbox Code Playgroud) python regression machine-learning scikit-learn sklearn-pandas
我有一个数据框df,如下所示。该列col2具有空值、空白值、整数甚至浮点值。new_df我想从中派生一个新的数据帧,df其中该列col2只有整数值。
import pandas as pd
import numpy as np
col1 = ["a", "b", "c", "d", "e", "f", "g", "h"]
col2 = ["25.45", "", "200", np.nan, "N/A", "null", "35", "5,300"]
df = pd.DataFrame({"col1": col1, "col2": col2})
Run Code Online (Sandbox Code Playgroud)
看起来是这样的df:
col1 col2
0 a 25.45
1 b
2 c 200
3 d NaN
4 e N/A
5 f null
6 g 35
7 h 5,300
Run Code Online (Sandbox Code Playgroud)
以下是我想要的输出,new_df其中列col2值仅为整数:
col1 col2 …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用tkinter创建一个简单的文本框。以下是我尝试使用的代码。
import tkinter as tk
from tkinter import simpledialog
root = tk.Tk() # Create an instance of tkinter
start_date = simpledialog.askstring(title = "Test Title",
prompt = "Entire Start Date in MM/DD/YYYY format:")
Run Code Online (Sandbox Code Playgroud)
以下是我得到的预期输出。
我的问题是,如何默认在空插槽中填充默认值,如下所示?
在R中,我可以使用以下命令轻松完成此操作。
start_date <- winDialogString("Entire Start Date in MM/DD/YYYY format:", "01/31/2018")
Run Code Online (Sandbox Code Playgroud) python ×5
r ×4
python-3.x ×3
dataframe ×2
html-email ×2
outlook ×2
rdcomclient ×2
css ×1
csv ×1
pandas ×1
regression ×1
scikit-learn ×1
selenium ×1
tk-toolkit ×1
tkinter ×1
web-scraping ×1
xtable ×1
zip ×1
zipfile ×1