按行读dataframe
for value in test.values:
print(value)
data = dict(zip(test.columns,value))
for ri,row in test.iterrows(): # 必须要加ri,要不然打印出来的结果不是一对一的
print(row)
print(ri)
print(dict(zip(test.columns,row)))
data = dict(zip(test.columns,row))
使用stack时,若数据中原先有NULL,fillna和未fillna的区别
fillna("NA")时会将即使原来为NULL的行也保留下来
d.read_csv(path,encoding='utf-8').set_index(index_columns).stack().reset_index().rename(columns=columns)

不进行赋值,会自动把原先为NULL的行删除掉
d.read_csv(path,encoding='utf-8').fillna("NA").set_index(index_columns).stack().reset_index().rename(columns=columns)

启示:数据减少的时候注意查看原因
lambda+fillna(method='ffill',axis=1)
在用assign和lambda 函数的时候,想要给某一列的NULL用另外一列赋值的时候,注意最后跟上想取列的列名,否则python会自动取前面的一列。
lambda x: x[['gs_correct','hgnc_id_map']].fillna(method='pad',axis=1)['hgnc_id_map']
取的是'hgnc_id_map'列
lambda x: x[['gs_correct','hgnc_id_map']].fillna(method='pad',axis=1)
取的是gs_correct列
replace("a",None)
replace任何字符串为None值时都是会填充上面一行的值,官网文档有解释。
如果想替换为空就写replace("a",'')

s = pd.Series([10, 'a', 'a', 'b', 'a'])
s.replace('a', None)

核对数据时发现excel中有的python中未查到
结果发现不是代码的问题,是excel不区分大小写的!!!
所以导致某个sequence只相差一个大小写,在excel中看到了,在python中处理后的数据没查到,是本来输入的sequence不对,错了一个字母的大小写。
pandas 使用 df.product 条件筛选报错Keyerror:False
这个列名可能是python的方法,试着用索引取列名就可以了,详见https://www.cnblogs.com/wanglvtao/p/10795779.html
tensorboard没有数据
在terminal 中输入命令tensorboard --logdir=logs --port=6007
如果显示没有数据的话原因是logs的路径是相对路径,需要把目录cd到log文件夹的上一层
axis
axis在apply函数中0代表列,1代表行;在drop函数中0代表行,1代表列
append/extend two list get None
a = [1,2,3]
b = [4,5,6]
c = a.extend(b) or c = a.append(b) or d.append(a.extend(b))都会get None,这是因为extend/append is an in-place function i.e. It will make the changes to the original list itself. From the docs Extend the list by appending all the items in the given list;
如果写成a.extend(b) print(a)则是两者合并之后的样子,就是不要赋值,三个的同样a.extend(b) d.append(a)。
如果非要赋值的,可以list = list1 + list2 or final_list = [*list_1, *list_2]
网友评论