python - Python pandas 特定的标头检查器
问题描述
我写了一个从 excel 文件中获取数据的 pandas python 代码。这是我正在使用的示例代码。但是一些excel文件没有一些标题,Abundance: F1: 127C, Sample
因此我如何检查计算。我正在考虑尝试除循环,但我不知道如何在可用循环之后列出。
非常感谢你。
# Here I am reading the excel file
Data=pd.read_excel("example.xlsx", header=0)
# Here I am taking the specific headers as list from the excel file
AccessionNum = list(Data['Accession'])
N_127_L = list(Data['Abundance: F1: 127N, Sample'])
C_127_L = list(Data['Abundance: F1: 127C, Sample'])
N_128_L = list(Data['Abundance: F1: 128N, Sample'])
C_128_L = list(Data['Abundance: F1: 128C, Sample'])
N_129_L = list(Data['Abundance: F1: 129N, Sample'])
C_129_L = list(Data['Abundance: F1: 129C, Sample'])
N_130_L = list(Data['Abundance: F1: 130N, Sample'])
C_130_L = list(Data['Abundance: F1: 130C, Sample'])
N_131_L = list(Data['Abundance: F1: 131N, Sample'])
j = 0
for i in AccessionNum:
# Here I am iterating the all of the rows
N_127 = N_127_L[j]
C_127 = C_127_L[j]
N_128 = N_128_L[j]
C_128 = C_128_L[j]
N_129 = N_129_L[j]
C_129 = C_129_L[j]
N_130 = N_130_L[j]
C_130 = C_130_L[j]
N_131 = N_131_L[j]
# Here I am grouping my columns but sometimes one or two doesn't have
dmsoList = [N_127, C_127, N_128]
drug1List = [C_128, N_129, C_129]
drug2List = [N_130, C_130, N_131]
# Here I am doing some calculation which is not important
dmso = statistics.mean(dmsoList)
drug1 = statistics.mean(drug1List)
drug2 = statistics.mean(drug2List)
log2_drug1 = '=LOG({}/{},2)'.format(drug1, dmso)
log2_drug2 = '=LOG({}/{},2)'.format(drug2, dmso)
ttest_drug1 = stats.ttest_ind(dmsoList, drug1List, equal_var=True)
ttest_drug2 = stats.ttest_ind(dmsoList, drug2List, equal_var=True)
log10_ttest_drug1 = '=-LOG({})'.format(ttest_drug1[1])
log10_ttest_drug2 = '=-LOG({})'.format(ttest_drug2[1])
Data.loc[j, 'Log2 Drug_1'] = log2_drug1
Data.loc[j, 'Log2 Drug_2'] = log2_drug2
Data.loc[j, '-log10 Drug_1 t-test'] = log10_ttest_drug1
Data.loc[j, '-log10 Drug_2 t-test'] = log10_ttest_drug2
j += 1
# Here I am outputting the data as excel file again
Data.to_excel('_Calculation.xlsx')
解决方案
推荐阅读
- sql - 如何根据 Postgres 中的固定时间间隔迭代表?
- javascript - Infura 为每个 eth_call 调用 eth_getBlockByNumber 十次
- javascript - Shopify 模块中未定义 React
- javascript - Knockout JS 根据页面 URL 显示隐藏 div
- node.js - 运行 npm ls
npm update 后不显示更新版本? - python - 如何将应用程序文件导入不同目录Python中的测试文件
- laravel - @cypress/vue 与 Laravel-Mix
- mysql - 如何恢复/恢复损坏的 RDS 实例?
- mysql - 在 MySQL 中存储 MatDatepicker 时间戳
- amazon-web-services - 当从 SQS 队列中删除一条消息时,配置了较高的可见性超时值,如果我删除该消息,它会立即被删除吗?