大熊猫多元线性回归分组并将结果保存为csv

时间:2016-02-02 01:59:23

标签: pandas regression

我正在尝试计算Y = CA列的线性回归,x = [' Plate X',' Plate Y'' Field X']和用Drum和Plate对这些值进行分组。其他问题 - 如何将结果保存为文件,csv更可取。 pandas包是否足以完成此任务或其他所需的包。 谢谢 有我的数据集:

DF = {'A': {0: 305.03277000000003,
  1: 304.42513500000001,
  2: 305.119575,
  3: 304.42513500000001,
  4: 304.07791500000002,
  5: 304.85916000000003,
  6: 305.72721000000001,
  7: 305.81401499999998,
  8: 304.07791500000002,
  9: 305.03277000000003,
  10: 304.68554999999998,
  11: 304.945965,
  12: 303.38347499999998,
  13: 304.945965,
  14: 304.51193999999998,
  15: 304.25152500000002,
  16: 304.51193999999998,
  17: 304.25152500000002,
  18: 304.42513500000001,
  19: 304.85916000000003,
  20: 303.8175,
  21: 305.119575,
  22: 304.59874500000001,
  23: 304.68554999999998,
  24: 304.33832999999998,
  25: 303.90430499999997,
  26: 304.68554999999998,
  27: 304.772355,
  28: 304.59874500000001,
  29: 304.772355,
  30: 304.59874500000001,
  31: 305.119575,
  32: 305.37998999999996,
  33: 304.59874500000001,
  34: 304.42513500000001,
  35: 304.33832999999998,
  36: 304.51193999999998,
  37: 305.46679499999999,
  38: 304.59874500000001,
  39: 305.29318499999999,
  40: 304.85916000000003,
  41: 305.29318499999999,
  42: 305.119575,
  43: 304.945965,
  44: 305.29318499999999,
  45: 304.85916000000003,
  46: 305.72721000000001,
  47: 306.16123500000003,
  48: 305.37998999999996,
  49: 305.03277000000003,
  50: 305.20637999999997,
  51: 304.51193999999998,
  52: 308.33136000000002,
  53: 305.81401499999998,
  54: 305.55360000000002,
  55: 306.42165,
  56: 305.64040499999999,
  57: 305.29318499999999,
  58: 305.37998999999996,
  59: 304.772355,
  60: 305.37998999999996,
  61: 305.72721000000001,
  62: 305.90082000000001,
  63: 305.64040499999999,
  64: 305.81401499999998,
  65: 304.85916000000003,
  66: 305.20637999999997,
  67: 306.42165,
  68: 305.64040499999999,
  69: 305.55360000000002,
  70: 304.59874500000001,
  71: 305.55360000000002,
  72: 306.07443000000001,
  73: 306.42165,
  74: 305.98762499999998,
  75: 306.68206499999997,
  76: 305.03277000000003,
  77: 305.46679499999999,
  78: 306.42165,
  79: 304.85916000000003,
  80: 304.51193999999998,
  81: 303.8175,
  82: 304.51193999999998,
  83: 304.16472000000005,
  84: 304.51193999999998,
  85: 303.73069500000003,
  86: 303.29667000000001,
  87: 304.68554999999998,
  88: 303.73069500000003,
  89: 304.42513500000001,
  90: 304.51193999999998,
  91: 304.16472000000005,
  92: 304.945965,
  93: 304.772355,
  94: 304.42513500000001,
  95: 304.16472000000005,
  96: 305.119575,
  97: 304.16472000000005,
  98: 304.25152500000002,
  99: 305.20637999999997},
 'B': {0: 311.10912000000002,
  1: 310.93551000000002,
  2: 313.279245,
  3: 313.19243999999998,
  4: 309.11260499999997,
  5: 309.0258,
  6: 309.72023999999999,
  7: 313.279245,
  8: 311.89036499999997,
  9: 311.19592499999999,
  10: 308.76538500000004,
  11: 309.72023999999999,
  12: 312.15078,
  13: 309.19941,
  14: 308.50497000000001,
  15: 308.33136000000002,
  16: 309.89384999999999,
  17: 310.848705,
  18: 312.23758500000002,
  19: 313.53966000000003,
  20: 309.72023999999999,
  21: 309.11260499999997,
  22: 311.89036499999997,
  23: 309.98065499999996,
  24: 309.19941,
  25: 310.41467999999998,
  26: 311.62995000000001,
  27: 311.02231499999999,
  28: 310.32787500000001,
  29: 310.06745999999998,
  30: 311.89036499999997,
  31: 311.89036499999997,
  32: 309.98065499999996,
  33: 312.06397500000003,
  34: 306.85567500000002,
  35: 309.98065499999996,
  36: 311.80356,
  37: 309.19941,
  38: 312.41119500000002,
  39: 310.848705,
  40: 311.10912000000002,
  41: 310.501485,
  42: 313.80007499999999,
  43: 308.24455499999999,
  44: 312.49799999999999,
  45: 313.10563500000001,
  46: 313.19243999999998,
  47: 309.63343500000002,
  48: 311.10912000000002,
  49: 310.501485,
  50: 310.58828999999997,
  51: 314.23410000000001,
  52: 312.41119500000002,
  53: 313.01882999999998,
  54: 311.19592499999999,
  55: 311.54314500000004,
  56: 313.279245,
  57: 311.54314500000004,
  58: 311.45634000000001,
  59: 313.19243999999998,
  60: 312.15078,
  61: 312.15078,
  62: 313.452855,
  63: 311.02231499999999,
  64: 311.02231499999999,
  65: 311.28272999999996,
  66: 311.02231499999999,
  67: 307.897335,
  68: 313.19243999999998,
  69: 311.97717,
  70: 311.10912000000002,
  71: 312.58480499999996,
  72: 312.58480499999996,
  73: 315.01534500000002,
  74: 311.97717,
  75: 313.452855,
  76: 311.80356,
  77: 308.67857999999995,
  78: 311.71675499999998,
  79: 311.36953499999998,
  80: 310.501485,
  81: 308.85219000000001,
  82: 311.10912000000002,
  83: 309.37302,
  84: 307.98413999999997,
  85: 311.10912000000002,
  86: 311.28272999999996,
  87: 310.93551000000002,
  88: 310.24107000000004,
  89: 307.11608999999999,
  90: 307.55011500000001,
  91: 308.76538500000004,
  92: 310.848705,
  93: 307.02928500000002,
  94: 309.89384999999999,
  95: 311.28272999999996,
  96: 307.81052999999997,
  97: 309.72023999999999,
  98: 311.54314500000004,
  99: 310.32787500000001},
 'C': {0: 305.72721000000001,
  1: 306.00498599999997,
  2: 306.49109399999998,
  3: 306.59526,
  4: 305.48415599999998,
  5: 305.24110200000001,
  6: 306.28276199999999,
  7: 306.97720199999998,
  8: 306.80359199999998,
  9: 307.081368,
  10: 306.10915199999999,
  11: 304.47721799999999,
  12: 305.24110200000001,
  13: 304.68554999999998,
  14: 306.35220600000002,
  15: 305.17165799999998,
  16: 306.45637200000004,
  17: 305.86609800000002,
  18: 306.734148,
  19: 306.28276199999999,
  20: 305.51887799999997,
  21: 308.053584,
  22: 306.52581600000002,
  23: 305.935542,
  24: 306.56053800000001,
  25: 306.10915199999999,
  26: 306.56053800000001,
  27: 305.79665399999999,
  28: 305.761932,
  29: 304.75499400000001,
  30: 306.07443000000001,
  31: 306.35220600000002,
  32: 305.86609800000002,
  33: 307.01192400000002,
  34: 306.28276199999999,
  35: 305.55360000000002,
  36: 306.35220600000002,
  37: 306.80359199999998,
  38: 305.90082000000001,
  39: 306.03970800000002,
  40: 307.18553399999996,
  41: 304.82443799999999,
  42: 305.83137599999998,
  43: 306.97720199999998,
  44: 306.38692799999995,
  45: 306.49109399999998,
  46: 306.38692799999995,
  47: 306.52581600000002,
  48: 305.06749200000002,
  49: 306.07443000000001,
  50: 306.56053800000001,
  51: 305.48415599999998,
  52: 305.69248799999997,
  53: 307.63692000000003,
  54: 307.28969999999998,
  55: 305.62304399999999,
  56: 306.38692799999995,
  57: 305.86609800000002,
  58: 306.56053800000001,
  59: 305.55360000000002,
  60: 306.07443000000001,
  61: 306.52581600000002,
  62: 306.56053800000001,
  63: 305.34526800000003,
  64: 305.24110200000001,
  65: 304.58138399999996,
  66: 307.04664600000001,
  67: 306.00498599999997,
  68: 305.79665399999999,
  69: 306.49109399999998,
  70: 305.51887799999997,
  71: 305.72721000000001,
  72: 306.31748399999998,
  73: 306.03970800000002,
  74: 307.15081200000003,
  75: 307.60219799999999,
  76: 304.92860400000001,
  77: 304.68554999999998,
  78: 305.58832200000001,
  79: 305.449434,
  80: 306.83831400000003,
  81: 306.49109399999998,
  82: 306.94247999999999,
  83: 304.963326,
  84: 307.25497799999999,
  85: 305.97026399999999,
  86: 306.07443000000001,
  87: 305.761932,
  88: 305.90082000000001,
  89: 306.31748399999998,
  90: 306.69942599999996,
  91: 306.07443000000001,
  92: 305.449434,
  93: 304.789716,
  94: 304.72027200000002,
  95: 306.10915199999999,
  96: 305.449434,
  97: 305.31054599999999,
  98: 305.31054599999999,
  99: 306.45637200000004},
 'C-A': {0: 0.69443999999999995,
  1: 1.5798510000000001,
  2: 1.3715190000000002,
  3: 2.1701250000000001,
  4: 1.4062410000000001,
  5: 0.381942,
  6: 0.55555200000000005,
  7: 1.163187,
  8: 2.7256770000000001,
  9: 2.0485980000000001,
  10: 1.423602,
  11: -0.46874700000000002,
  12: 1.8576270000000001,
  13: -0.26041500000000001,
  14: 1.840266,
  15: 0.92013299999999998,
  16: 1.9444319999999999,
  17: 1.614573,
  18: 2.3090130000000002,
  19: 1.423602,
  20: 1.7013779999999998,
  21: 2.9340090000000001,
  22: 1.927071,
  23: 1.249992,
  24: 2.2222080000000002,
  25: 2.204847,
  26: 1.8749880000000001,
  27: 1.0242990000000001,
  28: 1.163187,
  29: -0.017361000000000001,
  30: 1.4756850000000001,
  31: 1.232631,
  32: 0.48610799999999998,
  33: 2.413179,
  34: 1.8576270000000001,
  35: 1.2152700000000001,
  36: 1.840266,
  37: 1.336797,
  38: 1.3020750000000001,
  39: 0.74652299999999994,
  40: 2.3263739999999999,
  41: -0.46874700000000002,
  42: 0.71180100000000002,
  43: 2.031237,
  44: 1.0937430000000001,
  45: 1.631934,
  46: 0.65971800000000003,
  47: 0.36458099999999999,
  48: -0.312498,
  49: 1.04166,
  50: 1.354158,
  51: 0.97221599999999997,
  52: -2.6388720000000001,
  53: 1.822905,
  54: 1.7361,
  55: -0.79860600000000004,
  56: 0.74652299999999994,
  57: 0.57291300000000001,
  58: 1.1805479999999999,
  59: 0.78124499999999997,
  60: 0.69443999999999995,
  61: 0.79860600000000004,
  62: 0.65971800000000003,
  63: -0.29513699999999998,
  64: -0.57291300000000001,
  65: -0.27777600000000002,
  66: 1.840266,
  67: -0.41666400000000003,
  68: 0.156249,
  69: 0.93749400000000005,
  70: 0.92013299999999998,
  71: 0.17360999999999999,
  72: 0.24305399999999999,
  73: -0.381942,
  74: 1.163187,
  75: 0.92013299999999998,
  76: -0.10416600000000001,
  77: -0.78124499999999997,
  78: -0.83332800000000007,
  79: 0.59027399999999997,
  80: 2.3263739999999999,
  81: 2.673594,
  82: 2.4305400000000001,
  83: 0.79860600000000004,
  84: 2.7430380000000003,
  85: 2.2395689999999999,
  86: 2.7777599999999998,
  87: 1.0763819999999999,
  88: 2.1701250000000001,
  89: 1.8923490000000001,
  90: 2.1874860000000003,
  91: 1.9097099999999998,
  92: 0.50346899999999994,
  93: 0.017361000000000001,
  94: 0.29513699999999998,
  95: 1.9444319999999999,
  96: 0.32985900000000001,
  97: 1.145826,
  98: 1.059021,
  99: 1.249992},
 'Drum': {0: 'LAAA',
  1: 'LAAA',
  2: 'LAAA',
  3: 'LAAA',
  4: 'LAAA',
  5: 'LAAA',
  6: 'LAAA',
  7: 'LAAA',
  8: 'LAAA',
  9: 'LAAA',
  10: 'LAAA',
  11: 'LAAA',
  12: 'LAAA',
  13: 'LAAA',
  14: 'LAAA',
  15: 'LAAA',
  16: 'LAAA',
  17: 'LAAA',
  18: 'LAAA',
  19: 'LAAA',
  20: 'LAAA',
  21: 'LAAA',
  22: 'LAAA',
  23: 'LAAA',
  24: 'LAAA',
  25: 'LAAA',
  26: 'LAAA',
  27: 'LAAA',
  28: 'LAAA',
  29: 'LAAA',
  30: 'LAAA',
  31: 'LAAA',
  32: 'LAAA',
  33: 'LAAA',
  34: 'LAAA',
  35: 'LAAA',
  36: 'LAAA',
  37: 'LAAA',
  38: 'LAAA',
  39: 'LAAA',
  40: 'LAAA',
  41: 'LAAA',
  42: 'LAAA',
  43: 'LAAA',
  44: 'LAAA',
  45: 'LAAA',
  46: 'LAAA',
  47: 'LAAA',
  48: 'LAAA',
  49: 'LAAA',
  50: 'LAAA',
  51: 'LAAA',
  52: 'LAAA',
  53: 'LAAA',
  54: 'LAAA',
  55: 'LAAA',
  56: 'LAAA',
  57: 'LAAA',
  58: 'LAAA',
  59: 'LAAA',
  60: 'LAAA',
  61: 'LAAA',
  62: 'LAAA',
  63: 'LAAA',
  64: 'LAAA',
  65: 'LAAA',
  66: 'LAAA',
  67: 'LAAA',
  68: 'LAAA',
  69: 'LAAA',
  70: 'LAAA',
  71: 'LAAA',
  72: 'LAAA',
  73: 'LAAA',
  74: 'LAAA',
  75: 'LAAA',
  76: 'LAAA',
  77: 'LAAA',
  78: 'LAAA',
  79: 'LAAA',
  80: 'LAAA',
  81: 'LAAA',
  82: 'LAAA',
  83: 'LAAA',
  84: 'LAAA',
  85: 'LAAA',
  86: 'LAAA',
  87: 'LAAA',
  88: 'LAAA',
  89: 'LAAA',
  90: 'LAAA',
  91: 'LAAA',
  92: 'LAAA',
  93: 'LAAA',
  94: 'LAAA',
  95: 'LAAA',
  96: 'LAAA',
  97: 'LAAA',
  98: 'LAAA',
  99: 'LAAA'},
 'FIELD X': {0: 4.7949800000000007,
  1: -5.5198839999999993,
  2: 4.7949800000000007,
  3: 4.7949800000000007,
  4: -5.5198839999999993,
  5: 4.7949800000000007,
  6: -5.5198839999999993,
  7: 4.7949800000000007,
  8: 4.7949800000000007,
  9: -5.5198839999999993,
  10: -5.5198839999999993,
  11: 4.7949800000000007,
  12: 4.7949800000000007,
  13: -5.5198839999999993,
  14: 4.7949800000000007,
  15: -5.5198839999999993,
  16: 4.7949800000000007,
  17: -5.5198839999999993,
  18: 4.7949800000000007,
  19: 4.7949800000000007,
  20: -5.5198839999999993,
  21: 4.7949800000000007,
  22: -5.5198839999999993,
  23: 4.7949800000000007,
  24: 4.7949800000000007,
  25: -5.5198839999999993,
  26: 4.7949800000000007,
  27: -5.5198839999999993,
  28: -5.5198839999999993,
  29: 4.7949800000000007,
  30: -5.5198839999999993,
  31: 4.7949800000000007,
  32: 4.7949800000000007,
  33: -5.5198839999999993,
  34: 4.7949800000000007,
  35: -5.5198839999999993,
  36: 4.7949800000000007,
  37: -5.5198839999999993,
  38: 4.7949800000000007,
  39: -5.5198839999999993,
  40: 4.7949800000000007,
  41: -5.5198839999999993,
  42: 4.7949800000000007,
  43: -5.5198839999999993,
  44: 4.7949800000000007,
  45: -5.5198839999999993,
  46: 4.7949800000000007,
  47: -5.5198839999999993,
  48: 4.7949800000000007,
  49: -5.5198839999999993,
  50: -5.5198839999999993,
  51: 4.7949800000000007,
  52: -5.5198839999999993,
  53: 4.7949800000000007,
  54: 4.7949800000000007,
  55: -5.5198839999999993,
  56: 4.7949800000000007,
  57: -5.5198839999999993,
  58: 4.7949800000000007,
  59: -5.5198839999999993,
  60: 4.7949800000000007,
  61: 4.7949800000000007,
  62: -5.5198839999999993,
  63: 4.7949800000000007,
  64: -5.5198839999999993,
  65: 4.7949800000000007,
  66: 4.7949800000000007,
  67: -5.5198839999999993,
  68: 4.7949800000000007,
  69: -5.5198839999999993,
  70: -5.5198839999999993,
  71: 4.7949800000000007,
  72: -5.5198839999999993,
  73: 4.7949800000000007,
  74: -5.5198839999999993,
  75: 4.7949800000000007,
  76: -5.5198839999999993,
  77: -5.5198839999999993,
  78: 4.7949800000000007,
  79: -5.5198839999999993,
  80: 4.7949800000000007,
  81: -5.5198839999999993,
  82: 4.7949800000000007,
  83: 4.7949800000000007,
  84: -5.5198839999999993,
  85: 4.7949800000000007,
  86: -5.5198839999999993,
  87: 4.7949800000000007,
  88: 4.7949800000000007,
  89: -5.5198839999999993,
  90: -5.5198839999999993,
  91: 4.7949800000000007,
  92: 4.7949800000000007,
  93: -5.5198839999999993,
  94: 4.7949800000000007,
  95: -5.5198839999999993,
  96: 4.7949800000000007,
  97: -5.5198839999999993,
  98: 4.7949800000000007,
  99: 4.7949800000000007},
 'FIELD Y': {0: 1.8893500000000001,
  1: 1.8893500000000001,
  2: 1.8893500000000001,
  3: 1.8893500000000001,
  4: 1.8893500000000001,
  5: 1.8893500000000001,
  6: 1.8893500000000001,
  7: 1.8893500000000001,
  8: 1.8893500000000001,
  9: 1.8893500000000001,
  10: 1.8893500000000001,
  11: 1.8893500000000001,
  12: 1.8893500000000001,
  13: 1.8893500000000001,
  14: 1.8893500000000001,
  15: 1.8893500000000001,
  16: 1.8893500000000001,
  17: 1.8893500000000001,
  18: 1.8893500000000001,
  19: 1.8893500000000001,
  20: 1.8893500000000001,
  21: 1.8893500000000001,
  22: 1.8893500000000001,
  23: 1.8893500000000001,
  24: 1.8893500000000001,
  25: 1.8893500000000001,
  26: 1.8893500000000001,
  27: 1.8893500000000001,
  28: 1.8893500000000001,
  29: 1.8893500000000001,
  30: 1.8893500000000001,
  31: 1.8893500000000001,
  32: 1.8893500000000001,
  33: 1.8893500000000001,
  34: 1.8893500000000001,
  35: 1.8893500000000001,
  36: 1.8893500000000001,
  37: 1.8893500000000001,
  38: 1.8893500000000001,
  39: 1.8893500000000001,
  40: 1.8893500000000001,
  41: 1.8893500000000001,
  42: 1.8893500000000001,
  43: 1.8893500000000001,
  44: 1.8893500000000001,
  45: 1.8893500000000001,
  46: 1.8893500000000001,
  47: 1.8893500000000001,
  48: 1.8893500000000001,
  49: 1.8893500000000001,
  50: 1.8893500000000001,
  51: 1.8893500000000001,
  52: 1.8893500000000001,
  53: 1.8893500000000001,
  54: 1.8893500000000001,
  55: 1.8893500000000001,
  56: 1.8893500000000001,
  57: 1.8893500000000001,
  58: 1.8893500000000001,
  59: 1.8893500000000001,
  60: 1.8893500000000001,
  61: 1.8893500000000001,
  62: 1.8893500000000001,
  63: 1.8893500000000001,
  64: 1.8893500000000001,
  65: 1.8893500000000001,
  66: 1.8893500000000001,
  67: 1.8893500000000001,
  68: 1.8893500000000001,
  69: 1.8893500000000001,
  70: 1.8893500000000001,
  71: 1.8893500000000001,
  72: 1.8893500000000001,
  73: 1.8893500000000001,
  74: 1.8893500000000001,
  75: 1.8893500000000001,
  76: 1.8893500000000001,
  77: 1.8893500000000001,
  78: 1.8893500000000001,
  79: 1.8893500000000001,
  80: 1.8893500000000001,
  81: 1.8893500000000001,
  82: 1.8893500000000001,
  83: 1.8893500000000001,
  84: 1.8893500000000001,
  85: 1.8893500000000001,
  86: 1.8893500000000001,
  87: 1.8893500000000001,
  88: 1.8893500000000001,
  89: 1.8893500000000001,
  90: 1.8893500000000001,
  91: 1.8893500000000001,
  92: 1.8893500000000001,
  93: 1.8893500000000001,
  94: 1.8893500000000001,
  95: 1.8893500000000001,
  96: 1.8893500000000001,
  97: 1.8893500000000001,
  98: 1.8893500000000001,
  99: 1.8893500000000001},
 'Plate': {0: 72,
  1: 72,
  2: 72,
  3: 72,
  4: 72,
  5: 72,
  6: 72,
  7: 72,
  8: 72,
  9: 72,
  10: 72,
  11: 72,
  12: 72,
  13: 72,
  14: 72,
  15: 72,
  16: 72,
  17: 72,
  18: 72,
  19: 72,
  20: 72,
  21: 72,
  22: 72,
  23: 72,
  24: 72,
  25: 72,
  26: 72,
  27: 72,
  28: 72,
  29: 72,
  30: 72,
  31: 72,
  32: 72,
  33: 72,
  34: 72,
  35: 72,
  36: 72,
  37: 72,
  38: 72,
  39: 72,
  40: 72,
  41: 72,
  42: 72,
  43: 72,
  44: 72,
  45: 72,
  46: 72,
  47: 72,
  48: 72,
  49: 72,
  50: 72,
  51: 72,
  52: 72,
  53: 72,
  54: 72,
  55: 72,
  56: 72,
  57: 72,
  58: 72,
  59: 72,
  60: 72,
  61: 72,
  62: 72,
  63: 72,
  64: 72,
  65: 72,
  66: 72,
  67: 72,
  68: 72,
  69: 72,
  70: 72,
  71: 72,
  72: 72,
  73: 72,
  74: 72,
  75: 72,
  76: 72,
  77: 72,
  78: 72,
  79: 72,
  80: 131,
  81: 131,
  82: 131,
  83: 131,
  84: 131,
  85: 131,
  86: 131,
  87: 131,
  88: 131,
  89: 131,
  90: 131,
  91: 131,
  92: 131,
  93: 131,
  94: 131,
  95: 131,
  96: 131,
  97: 131,
  98: 131,
  99: 131},
 'Plate X': {0: -134.13406000000001,
  1: -134.13406000000001,
  2: -134.13406000000001,
  3: -113.50433200000001,
  4: -113.50433200000001,
  5: -113.50433200000001,
  6: -113.50433200000001,
  7: -113.50433200000001,
  8: -92.874604000000005,
  9: -92.874604000000005,
  10: -92.874604000000005,
  11: -92.874604000000005,
  12: -72.244876000000005,
  13: -72.244876000000005,
  14: -72.244876000000005,
  15: -72.244876000000005,
  16: -72.244876000000005,
  17: -72.244876000000005,
  18: -72.244876000000005,
  19: -51.615147999999998,
  20: -51.615147999999998,
  21: -51.615147999999998,
  22: -51.615147999999998,
  23: -51.615147999999998,
  24: -30.985420000000001,
  25: -30.985420000000001,
  26: -30.985420000000001,
  27: -30.985420000000001,
  28: -30.985420000000001,
  29: -30.985420000000001,
  30: -30.985420000000001,
  31: -30.985420000000001,
  32: -10.355691999999999,
  33: -10.355691999999999,
  34: -10.355691999999999,
  35: -10.355691999999999,
  36: -10.355691999999999,
  37: -10.355691999999999,
  38: -10.355691999999999,
  39: 10.274036000000001,
  40: 10.274036000000001,
  41: 10.274036000000001,
  42: 10.274036000000001,
  43: 10.274036000000001,
  44: 10.274036000000001,
  45: 10.274036000000001,
  46: 30.903764000000002,
  47: 30.903764000000002,
  48: 30.903764000000002,
  49: 30.903764000000002,
  50: 30.903764000000002,
  51: 30.903764000000002,
  52: 30.903764000000002,
  53: 30.903764000000002,
  54: 51.533491999999995,
  55: 51.533491999999995,
  56: 51.533491999999995,
  57: 51.533491999999995,
  58: 51.533491999999995,
  59: 51.533491999999995,
  60: 51.533491999999995,
  61: 72.163219999999995,
  62: 72.163219999999995,
  63: 72.163219999999995,
  64: 72.163219999999995,
  65: 72.163219999999995,
  66: 72.163219999999995,
  67: 92.792947999999996,
  68: 92.792947999999996,
  69: 92.792947999999996,
  70: 92.792947999999996,
  71: 92.792947999999996,
  72: 113.422676,
  73: 113.422676,
  74: 113.422676,
  75: 113.422676,
  76: 113.422676,
  77: 134.052404,
  78: 134.052404,
  79: 134.052404,
  80: -134.13406000000001,
  81: -134.13406000000001,
  82: -134.13406000000001,
  83: -113.50433200000001,
  84: -113.50433200000001,
  85: -113.50433200000001,
  86: -113.50433200000001,
  87: -113.50433200000001,
  88: -92.874604000000005,
  89: -92.874604000000005,
  90: -92.874604000000005,
  91: -92.874604000000005,
  92: -72.244876000000005,
  93: -72.244876000000005,
  94: -72.244876000000005,
  95: -72.244876000000005,
  96: -72.244876000000005,
  97: -72.244876000000005,
  98: -72.244876000000005,
  99: -51.615147999999998},
 'Plate Y': {0: -27.0123,
  1: 0.039899999999999998,
  2: 27.092099999999999,
  3: -81.116699999999994,
  4: -54.064500000000002,
  5: 0.039899999999999998,
  6: 54.144300000000001,
  7: 81.1965,
  8: -54.064500000000002,
  9: -27.0123,
  10: 27.092099999999999,
  11: 54.144300000000001,
  12: -108.16889999999999,
  13: -81.116699999999994,
  14: -27.0123,
  15: 0.039899999999999998,
  16: 27.092099999999999,
  17: 81.1965,
  18: 108.2487,
  19: -81.116699999999994,
  20: -54.064500000000002,
  21: 0.039899999999999998,
  22: 54.144300000000001,
  23: 81.1965,
  24: -135.22110000000001,
  25: -108.16889999999999,
  26: -54.064500000000002,
  27: -27.0123,
  28: 27.092099999999999,
  29: 54.144300000000001,
  30: 108.2487,
  31: 135.30090000000001,
  32: -108.16889999999999,
  33: -81.116699999999994,
  34: -27.0123,
  35: 0.039899999999999998,
  36: 27.092099999999999,
  37: 81.1965,
  38: 108.2487,
  39: -135.22110000000001,
  40: -81.116699999999994,
  41: -54.064500000000002,
  42: 0.039899999999999998,
  43: 54.144300000000001,
  44: 81.1965,
  45: 135.30090000000001,
  46: -135.22110000000001,
  47: -108.16889999999999,
  48: -54.064500000000002,
  49: -27.0123,
  50: 27.092099999999999,
  51: 54.144300000000001,
  52: 108.2487,
  53: 135.30090000000001,
  54: -108.16889999999999,
  55: -81.116699999999994,
  56: -27.0123,
  57: 0.039899999999999998,
  58: 27.092099999999999,
  59: 81.1965,
  60: 108.2487,
  61: -81.116699999999994,
  62: -54.064500000000002,
  63: 0.039899999999999998,
  64: 54.144300000000001,
  65: 81.1965,
  66: 108.2487,
  67: -108.16889999999999,
  68: -54.064500000000002,
  69: -27.0123,
  70: 27.092099999999999,
  71: 54.144300000000001,
  72: -81.116699999999994,
  73: -27.0123,
  74: 0.039899999999999998,
  75: 27.092099999999999,
  76: 81.1965,
  77: -54.064500000000002,
  78: 0.039899999999999998,
  79: 54.144300000000001,
  80: -27.0123,
  81: 0.039899999999999998,
  82: 27.092099999999999,
  83: -81.116699999999994,
  84: -54.064500000000002,
  85: 0.039899999999999998,
  86: 54.144300000000001,
  87: 81.1965,
  88: -54.064500000000002,
  89: -27.0123,
  90: 27.092099999999999,
  91: 54.144300000000001,
  92: -108.16889999999999,
  93: -81.116699999999994,
  94: -27.0123,
  95: 0.039899999999999998,
  96: 27.092099999999999,
  97: 81.1965,
  98: 108.2487,
  99: -81.116699999999994},
 'Unnamed: 0': {0: 0,
  1: 1,
  2: 2,
  3: 3,
  4: 4,
  5: 5,
  6: 6,
  7: 7,
  8: 8,
  9: 9,
  10: 10,
  11: 11,
  12: 12,
  13: 13,
  14: 14,
  15: 15,
  16: 16,
  17: 17,
  18: 18,
  19: 19,
  20: 20,
  21: 21,
  22: 22,
  23: 23,
  24: 24,
  25: 25,
  26: 26,
  27: 27,
  28: 28,
  29: 29,
  30: 30,
  31: 31,
  32: 32,
  33: 33,
  34: 34,
  35: 35,
  36: 36,
  37: 37,
  38: 38,
  39: 39,
  40: 40,
  41: 41,
  42: 42,
  43: 43,
  44: 44,
  45: 45,
  46: 46,
  47: 47,
  48: 48,
  49: 49,
  50: 50,
  51: 51,
  52: 52,
  53: 53,
  54: 54,
  55: 55,
  56: 56,
  57: 57,
  58: 58,
  59: 59,
  60: 60,
  61: 61,
  62: 62,
  63: 63,
  64: 64,
  65: 65,
  66: 66,
  67: 67,
  68: 68,
  69: 69,
  70: 70,
  71: 71,
  72: 72,
  73: 73,
  74: 74,
  75: 75,
  76: 76,
  77: 77,
  78: 78,
  79: 79,
  80: 80,
  81: 81,
  82: 82,
  83: 83,
  84: 84,
  85: 85,
  86: 86,
  87: 87,
  88: 88,
  89: 89,
  90: 90,
  91: 91,
  92: 92,
  93: 93,
  94: 94,
  95: 95,
  96: 96,
  97: 97,
  98: 98,
  99: 99}}

1 个答案:

答案 0 :(得分:2)

从您的问题来看,它听起来并不像您想要多元回归(即多个Y' s)。如果你只是从多个X预测单个Y,你可以用pandas这样做,然后将结果保存到txt文件:

import pandas as pd

df = pd.DataFrame(DF)

res = pd.stats.api.ols(y=df['C-A'], x=df[['Plate X','Plate Y','FIELD X']])

file = open("C:/Users/Simon/Desktop/results.txt", "w")

file.write(str(res))

file.close()

您在问题中提到要按Drum和Plate分组分析。但是,Drum行的每个值都相同。但是,如果要按Plate分组,然后在每个子组上运行OLS,则可以执行以下操作:

import pandas as pd

df = pd.DataFrame(DF)

results = []

def ols_res(df):
    results.append( pd.stats.api.ols(y=df['C-A'], x=df[['Plate X','Plate Y','FIELD X']]))

df.groupby('Plate').apply(lambda newdf: ols_res(newdf))

file = open("C:/Users/Simon/Desktop/results.txt", "w")

for el in results:
    file.write(str(el))

file.close()

如果您还希望按鼓分组,并记下每个分析所针对的鼓/盘组合,您可以执行类似的操作,只需在结果文件中添加一些额外的txt:

import pandas as pd

df = pd.DataFrame(DF)

results = []

def ols_res(df):
    curCombo = "plate:" + str(df["Plate"].mean()) + ", drum:" + str(df["Drum"].unique())
    regression_results = pd.stats.api.ols(y=df['C-A'], x=df[['Plate X','Plate Y','FIELD X']])
    results.append([curCombo, regression_results])


df.groupby(['Plate', 'Drum']).apply(lambda newdf: ols_res(newdf))

file = open("C:/Users/Simon/Desktop/results.txt", "w")

for el in results:
    file.write(str(el))
    file.write("\n\n")

file.close()