读取.csv文件
data=pd.read_csv(r'name.csv',encoding='utf-8')
pandas (inplace = True)
这个东西呢
data = pd.DataFrame
data.Function(##,##,...,inplace = True)
# 等价于
# data = data.Function(##,##,...,inplace = False)
pd.Dataframe
添加表头
a = pd.Dataframe(matrix)
a.columns = ['第一列','第二列']
处理缺失值,把缺失值填满为None,但是这样是在这个缺失值填一个None值,如果输出成csv看不到,这个方法不错,省的报错
df = pd.Dataframe()
df.fillna(value="None")
切片
df = pd.Dataframe()
a = df.iloc[:,2:]
# a是所有行,第二列往后
# 是iloc,loc不行
获取pd.Dataframe 列名
x = pd.Dataframe()
x.columns
pandas判断为空
if pd.isna(data[i]):
###
pandas删除空行
data = pd.read_csv(r'name.csv',encoding='utf-8')
data.dropna(axis=0, how='any', inplace=True)
# how = any 只要行中有空值就删掉
data.to_csv('aa.csv')
pandas to_list()
data = pd.read_csv(r'name.csv',encoding='utf-8')
drug_number = data['0'].tolist() # 需要指明列标
print(drug_number)
pandas 删除指定行,这个行名是一个list
data = pd.read_csv(r'name.csv',encoding='utf-8')
data.drop(index = [0,1]) # 删除0,1行
将整个df按照某一列数值大小进行排序
data = pd.read_csv(r'name.csv',encoding='utf-8')
data.sort_values('Odds Ratio',inplace=True)
numpy 删除指定行,这个行名是一个list
to_delete = [1,3,5] # 指定删除1,3,5行
data = np.delete(data,to_delete,axis=0)
|