做过很多尝试,将数据集中的0值去掉也不行。因为数据集2是可以正常出结果的,照着它的样子改动,把月份改成字母还是不行。
#coding:utf8
from scipy import stats
import pandas as pd
import numpy as np
from statsmodels.formula.api import ols
from statsmodels.stats.anova import anova_lm
from statsmodels.stats.multicomp import pairwise_tukeyhsd
import matplotlib.pyplot as plt
path = r"E:python codezuoye2facter-avaon.csv"
df = pd.read_csv(path,header=None,names=['data','month','time'] )
formula = 'data~C(time) + C(month) + C(time):C(month)'
anova_results = anova_lm(ols(formula,df).fit())
print(anova_results)
运行结果是这样的
数据集1(是我想要分析的)
1,4574.82,Jan,8
2,32136.71,Jan,9
3,73890.49,Jan,10
4,61498.92,Jan,11
5,38142.71,Jan,12
6,45988.9,Jan,13
7,66276.1,Jan,14
8,82821.365,Jan,15
9,81560.06,Jan,16
10,78350.47,Jan,17
11,80930.74,Jan,18
12,95226.79,Jan,19
13,75982.9,Jan,20
14,14012.17,Jan,21
15,4574.82,Feb,8
16,32136.71,Feb,9
17,73890.49,Feb,10
18,61498.92,Feb,11
19,38142.71,Feb,12
20,45988.9,Feb,13
21,66276.1,Feb,14
22,82821.365,Feb,15
23,81560.06,Feb,16
24,78350.47,Feb,17
25,80930.74,Feb,18
26,95226.79,Feb,19
27,75982.9,Feb,20
28,14012.17,Feb,21
数据集2(从网上教程中下的,可以正常出结果)
len supp dose
1 4.2 VC 0.5
2 11.5 VC 0.5
3 7.3 VC 0.5
4 5.8 VC 0.5
5 6.4 VC 0.5
6 10 VC 0.5
7 11.2 VC 0.5
8 11.2 VC 0.5
9 5.2 VC 0.5
10 7 VC 0.5
11 16.5 VC 1
12 16.5 VC 1
13 15.2 VC 1
14 17.3 VC 1
15 22.5 VC 1
16 17.3 VC 1
17 13.6 VC 1
18 14.5 VC 1
19 18.8 VC 1
20 15.5 VC 1
21 23.6 VC 2
22 18.5 VC 2
23 33.9 VC 2
24 25.5 VC 2
25 26.4 VC 2
26 32.5 VC 2
27 26.7 VC 2
28 21.5 VC 2
29 23.3 VC 2
30 29.5 VC 2
31 15.2 OJ 0.5
32 21.5 OJ 0.5
33 17.6 OJ 0.5
34 9.7 OJ 0.5
35 14.5 OJ 0.5
36 10 OJ 0.5
37 8.2 OJ 0.5
38 9.4 OJ 0.5
39 16.5 OJ 0.5
40 9.7 OJ 0.5
41 19.7 OJ 1
42 23.3 OJ 1
43 23.6 OJ 1
44 26.4 OJ 1
45 20 OJ 1
46 25.2 OJ 1
47 25.8 OJ 1
48 21.2 OJ 1
49 14.5 OJ 1
50 27.3 OJ 1
51 25.5 OJ 2
52 26.4 OJ 2
53 22.4 OJ 2
54 24.5 OJ 2
55 24.8 OJ 2
56 30.9 OJ 2
57 26.4 OJ 2
58 27.3 OJ 2
59 29.4 OJ 2
60 23 OJ 2
![clipboard.png](/img/bVLHoD)