title: An R Markdown document converted from "lesson5-1_data_basic.ipynb"
output: html_document
安装需要的包
#!pip install matplotlib==3.2.2 -i https://mirrors.aliyun.com/pypi/simple
#!pip install -r libs.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
# pip install matplotlib
# pip install matplotlib==3.2.2
# pip install matplotlib -i https://pypi.tuna.tsinghua.edu.cn/simple
# pip install -r libs.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
# !pip install jupyter_contrib_nbextensions
excel的读写
读取
import pandas as pd# 导入第三方库
dir(pandas)
import pandas as pd
filename = r'../data/spine_dataset.csv'# 相对路径
raw = pd.read_csv(filename)# 读取文件获得表格
# 绝对路径和相对路径
# ../ 上级目录
#./当前目录
常用操作
删除列
# raw = raw.drop(columns=['Unnamed: 0'])
# display(raw)
raw.drop(columns=['Overall survival'],inplace=True)
raw_new = raw
选择列
raw.colnames
raw[['target']]
raw[ ['Survival months','Disease specific survival'] ]
dir(raw)
raw.columns
raw1 = raw.drop(columns=['Overall survival'])
raw.columns
raw1.columns
选择行
raw.columns
# raw.index
# raw.loc[0]
raw.loc[ [0,2,5] ]
raw[["Survival months"]]
保存
filename_saved = '../spine_my_save.csv'
raw.to_csv(filename_saved)
网友评论