散布図を作成するために使用している pandas にデータフレームがあり、プロットに回帰直線を含めたいと考えています。今、私はポリフィットでこれをやろうとしています。
これが私のコードです:
import pandas as pd
import matplotlib
import matplotlib.pyplot as plt
from numpy import *
table1 = pd.DataFrame.from_csv('upregulated_genes.txt', sep='\t', header=0, index_col=0)
table2 = pd.DataFrame.from_csv('misson_genes.txt', sep='\t', header=0, index_col=0)
table1 = table1.join(table2, how='outer')
table1 = table1.dropna(how='any')
table1 = table1.replace('#DIV/0!', 0)
# scatterplot
plt.scatter(table1['log2 fold change misson'], table1['log2 fold change'])
plt.ylabel('log2 expression fold change')
plt.xlabel('log2 expression fold change Misson et al. 2005')
plt.title('Root Early Upregulated Genes')
plt.axis([0,12,-5,12])
# this is the part I'm unsure about
regres = polyfit(table1['log2 fold change misson'], table1['log2 fold change'], 1)
plt.show()
しかし、次のエラーが表示されます。
TypeError: cannot concatenate 'str' and 'float' objects
ここで私がどこで間違っているのか誰か知っていますか? プロットに回帰直線を追加する方法もわかりません。私のコードに関するその他の一般的なコメントも大歓迎です。私はまだ初心者です。