R语言读取数据
read.csv 与 read.table
两个函数相似,都可以读取分隔符分割的数据,多为txt、csv形式。但是一些默认分割符号和标题不同:
read.table(file, header = FALSE, sep = "")
read.csv(file, header = TRUE, sep = ",")
read.csv2(file, header = TRUE, sep = ";")
csv的意思就是逗号分隔Comma Seperate Values
其他参数:fill=T
填充空格;stripe.white
去除前后空格;skip
跳过某一行;encoding
确定编码形式
readLines/readLine
读取txt,每一行都读取或只读取一行
read_excel
读取excel文件,需要导入包library(readxl)
scan
从剪贴板批量导入
python读取数据
pd.read_csv
读取csv文件
pd.read_excel
读取excel文件
读取txt
需要先打开txt文件
读取到字符串中:
f = open('1.txt')
strl = f.read()
读取到列表中:
line = f.readlines()
或
for line in f:
data.apend(line)