Category comparison - pandas
I have the following dataframe:
{
'views_per_day': {0: 37, 1: 26, 2: 10, 3: 17, 4: 5, 5: 13, 6: 5, 7: 15, 8: 7, 9: 7, 10: 3, 11: 13, 12: 9, 13: 27, 14: 13, 15: 6, 16: 17, 17: 12, 18: 9, 19: 16, 20: 6, 21: 11, 22: 5, 23: 12, 24: 10, 25: 4, 26: 12, 27: 8, 28: 9, 29: 8, 30: 11, 31: 18, 32: 15, 33: 4, 34: 8, 35: 7, 36: 8, 37: 8, 38: 5, 39: 8, 40: 10, 41: 33, 42: 8, 43: 7, 44: 7, 45: 7, 46: 7, 47: 7, 48: 6, 49: 7, 50: 6, 51: 5, 52: 3, 53: 6, 54: 13, 55: 6, 56: 6, 57: 7, 58: 6, 59: 5, 60: 4, 61: 5, 62: 6, 63: 6, 64: 3, 65: 6, 66: 6, 67: 4, 68: 5, 69: 4, 70: 6, 71: 5, 72: 5, 73: 3, 74: 4, 75: 5, 76: 8, 77: 30, 78: 9, 79: 5, 80: 5, 81: 6, 82: 5, 83: 4, 84: 7, 85: 4, 86: 4, 87: 5, 88: 3, 89: 3, 90: 7, 91: 3, 92: 4, 93: 8, 94: 2, 95: 3, 96: 5, 97: 4, 98: 4, 99: 4, 100: 4, 101: 4, 102: 4, 103: 3, 104: 4, 105: 6, 106: 3, 107: 3, 108: 3, 109: 3, 110: 3, 111: 3, 112: 4, 113: 3, 114: 3, 115: 4, 116: 3, 117: 3, 118: 2, 119: 3, 120: 3, 121: 2, 122: 4, 123: 4, 124: 4, 125: 26, 126: 3, 127: 3, 128: 5, 129: 3, 130: 2, 131: 4, 132: 3, 133: 4, 134: 3, 135: 4, 136: 3, 137: 3, 138: 5, 139: 2, 140: 5, 141: 3, 142: 3, 143: 4, 144: 3, 145: 3, 146: 4, 147: 4, 148: 7, 149: 3, 150: 3, 151: 3, 152: 2, 153: 3, 154: 12, 155: 3, 156: 2, 157: 3, 158: 2, 159: 2, 160: 3, 161: 4, 162: 2, 163: 2, 164: 4, 165: 3, 166: 3, 167: 5, 168: 1, 169: 2, 170: 11, 171: 3, 172: 2, 173: 4, 174: 4, 175: 2, 176: 6, 177: 2, 178: 4, 179: 2, 180: 3, 181: 2, 182: 2, 183: 2, 184: 2, 185: 2, 186: 2, 187: 2, 188: 3, 189: 2, 190: 3, 191: 2, 192: 2, 193: 2, 194: 3, 195: 3, 196: 2, 197: 2, 198: 2, 199: 3, 200: 2, 201: 2, 202: 2, 203: 2, 204: 3, 205: 2, 206: 2, 207: 2, 208: 1, 209: 5, 210: 2, 211: 2, 212: 2, 213: 5, 214: 3, 215: 3, 216: 1, 217: 2, 218: 2, 219: 1, 220: 2, 221: 2, 222: 3, 223: 3, 224: 2, 225: 1, 226: 4, 227: 1, 228: 1, 229: 2, 230: 2, 231: 4, 232: 1, 233: 2, 234: 1, 235: 1, 236: 2, 237: 2, 238: 2, 239: 8, 240: 2, 241: 2, 242: 1, 243: 2, 244: 1, 245: 1, 246: 2, 247: 1, 248: 1, 249: 2, 250: 3, 251: 4, 252: 4, 253: 1, 254: 41, 255: 28, 256: 59, 257: 35, 258: 11, 259: 12, 260: 12, 261: 8, 262: 6, 263: 8, 264: 10, 265: 15, 266: 15, 267: 5, 268: 8, 269: 15, 270: 11, 271: 16, 272: 11, 273: 12, 274: 11, 275: 5, 276: 9, 277: 10, 278: 20, 279: 5, 280: 11, 281: 5, 282: 7, 283: 9, 284: 9, 285: 9, 286: 9, 287: 4, 288: 9, 289: 4, 290: 6, 291: 4, 292: 8, 293: 3, 294: 9, 295: 9, 296: 9, 297: 5, 298: 4, 299: 10, 300: 18, 301: 4, 302: 5, 303: 5, 304: 11, 305: 9, 306: 7, 307: 4, 308: 7, 309: 9, 310: 5, 311: 4, 312: 8, 313: 3, 314: 7, 315: 12, 316: 3, 317: 6, 318: 6, 319: 6, 320: 6, 321: 7, 322: 6, 323: 6, 324: 8, 325: 6, 326: 3, 327: 6, 328: 4, 329: 4, 330: 4, 331: 7, 332: 6, 333: 10, 334: 3, 335: 5, 336: 6, 337: 13, 338: 12, 339: 3, 340: 5, 341: 5, 342: 4, 343: 5, 344: 3, 345: 3, 346: 5, 347: 4, 348: 5, 349: 2, 350: 5, 351: 5, 352: 13, 353: 10, 354: 7, 355: 2, 356: 3, 357: 5, 358: 4, 359: 7, 360: 4, 361: 4, 362: 4, 363: 6, 364: 5, 365: 4, 366: 4, 367: 6, 368: 6, 369: 5, 370: 4, 371: 4, 372: 2, 373: 3, 374: 4, 375: 4, 376: 4, 377: 4, 378: 4, 379: 4, 380: 4, 381: 2, 382: 3, 383: 4, 384: 2, 385: 4, 386: 4, 387: 4, 388: 5, 389: 3, 390: 3, 391: 4, 392: 3, 393: 3, 394: 3, 395: 2, 396: 4, 397: 3, 398: 2, 399: 3, 400: 2, 401: 4, 402: 3, 403: 3, 404: 4, 405: 3, 406: 4, 407: 4, 408: 5, 409: 3, 410: 6, 411: 3, 412: 3, 413: 2, 414: 3, 415: 3, 416: 3, 417: 3, 418: 1, 419: 2, 420: 5, 421: 4, 422: 3, 423: 2, 424: 3, 425: 3, 426: 3, 427: 2, 428: 3, 429: 3, 430: 3, 431: 3, 432: 2, 433: 3, 434: 3, 435: 2, 436: 2, 437: 3, 438: 2, 439: 2, 440: 4, 441: 16, 442: 2, 443: 2, 444: 2, 445: 2, 446: 2, 447: 2, 448: 2, 449: 2, 450: 2, 451: 3, 452: 3, 453: 2, 454: 2, 455: 2, 456: 4, 457: 2, 458: 3, 459: 2, 460: 2, 461: 2, 462: 2, 463: 1, 464: 3, 465: 3, 466: 2, 467: 2, 468: 18, 469: 2, 470: 2, 471: 2, 472: 5, 473: 2, 474: 3, 475: 2, 476: 2, 477: 2, 478: 2, 479: 2, 480: 1, 481: 4, 482: 2, 483: 2, 484: 2, 485: 2, 486: 3, 487: 2, 488: 2, 489: 6, 490: 1, 491: 3, 492: 2, 493: 1, 494: 2, 495: 3, 496: 3, 497: 2, 498: 1, 499: 2, 500: 1, 501: 1, 502: 1, 503: 1, 504: 1, 505: 1, 506: 3, 507: 4, 508: 2, 509: 2, 510: 1, 511: 1, 512: 2, 513: 2, 514: 2, 515: 2, 516: 1, 517: 1, 518: 1, 519: 1, 520: 1, 521: 3, 522: 11, 523: 2, 524: 1, 525: 48, 526: 51, 527: 20, 528: 26, 529: 23, 530: 8, 531: 6, 532: 17, 533: 17, 534: 15, 535: 12, 536: 17, 537: 14, 538: 12, 539: 18, 540: 11, 541: 14, 542: 10, 543: 7, 544: 13, 545: 10, 546: 10, 547: 5, 548: 8, 549: 7, 550: 7, 551: 9, 552: 5, 553: 8, 554: 19, 555: 5, 556: 14, 557: 11, 558: 7, 559: 5, 560: 6, 561: 8, 562: 8, 563: 12, 564: 8, 565: 7, 566: 4, 567: 7, 568: 8, 569: 9, 570: 4, 571: 6, 572: 7, 573: 14, 574: 5, 575: 4, 576: 6, 577: 8, 578: 6, 579: 6, 580: 3, 581: 3, 582: 6, 583: 3, 584: 3, 585: 7, 586: 6, 587: 4, 588: 11, 589: 6, 590: 4, 591: 5, 592: 5, 593: 4, 594: 7, 595: 5, 596: 5, 597: 3, 598: 7, 599: 5, 600: 5, 601: 4, 602: 5, 603: 4, 604: 4, 605: 5, 606: 5, 607: 5, 608: 4, 609: 3, 610: 6, 611: 4, 612: 5, 613: 4, 614: 4, 615: 4, 616: 4, 617: 5, 618: 4, 619: 4, 620: 5, 621: 4, 622: 4, 623: 2, 624: 4, 625: 4, 626: 3, 627: 7, 628: 2, 629: 4, 630: 4, 631: 7, 632: 3, 633: 4, 634: 4, 635: 3, 636: 3, 637: 3, 638: 4, 639: 3, 640: 3, 641: 2, 642: 3, 643: 2, 644: 3, 645: 3, 646: 3, 647: 3, 648: 3, 649: 3, 650: 3, 651: 4, 652: 2, 653: 5, 654: 4, 655: 4, 656: 5, 657: 4, 658: 3, 659: 3, 660: 2, 661: 6, 662: 2, 663: 4, 664: 3, 665: 3, 666: 2, 667: 4, 668: 4, 669: 7, 670: 3, 671: 2, 672: 2, 673: 6, 674: 2, 675: 2, 676: 2, 677: 2, 678: 2, 679: 4, 680: 3, 681: 3, 682: 2, 683: 3, 684: 3, 685: 2, 686: 2, 687: 3, 688: 3, 689: 2, 690: 2, 691: 2, 692: 2, 693: 2, 694: 2, 695: 2, 696: 4, 697: 2, 698: 5, 699: 2, 700: 2, 701: 3, 702: 2, 703: 2, 704: 3, 705: 2, 706: 3, 707: 2, 708: 3, 709: 2, 710: 2, 711: 2, 712: 2, 713: 2, 714: 2, 715: 2, 716: 2, 717: 2, 718: 2, 719: 2, 720: 3, 721: 3, 722: 2, 723: 2, 724: 2, 725: 2, 726: 3, 727: 2, 728: 2, 729: 2, 730: 2, 731: 2, 732: 2, 733: 2, 734: 2, 735: 2, 736: 2, 737: 2, 738: 2, 739: 2, 740: 2, 741: 2, 742: 2, 743: 1, 744: 2, 745: 2, 746: 2, 747: 2, 748: 2, 749: 2, 750: 2, 751: 2, 752: 1, 753: 4, 754: 4, 755: 1, 756: 1, 757: 1, 758: 3, 759: 5, 760: 2, 761: 2, 762: 1, 763: 2, 764: 2, 765: 2, 766: 1, 767: 2, 768: 1, 769: 1, 770: 1, 771: 2, 772: 1, 773: 1, 774: 1, 775: 1, 776: 1, 777: 1, 778: 1},
'status': {0: 'Extra', 1: 'Extra', 2: 'Extra', 3: 'Standard', 4: 'Extra', 5: 'Extra', 6: 'Extra', 7: 'Extra', 8: 'Standard', 9: 'Extra', 10: 'Extra', 11: 'Extra', 12: 'Extra', 13: 'Extra', 14: 'Standard', 15: 'Extra', 16: 'Extra', 17: 'Extra', 18: 'Extra', 19: 'Extra', 20: 'Extra', 21: 'Standard', 22: 'Standard', 23: 'Extra', 24: 'Standard', 25: 'Extra', 26: 'Extra', 27: 'Standard', 28: 'Extra', 29: 'Standard', 30: 'Extra', 31: 'Standard', 32: 'Extra', 33: 'Extra', 34: 'Standard', 35: 'Standard', 36: 'Standard', 37: 'Standard', 38: 'Standard', 39: 'Standard', 40: 'Extra', 41: 'Standard', 42: 'Extra', 43: 'Standard', 44: 'Standard', 45: 'Extra', 46: 'Standard', 47: 'Standard', 48: 'Standard', 49: 'Standard', 50: 'Standard', 51: 'Standard', 52: 'Standard', 53: 'Extra', 54: 'Standard', 55: 'Extra', 56: 'Standard', 57: 'Extra', 58: 'Standard', 59: 'Standard', 60: 'Extra', 61: 'Standard', 62: 'Extra', 63: 'Standard', 64: 'Extra', 65: 'Standard', 66: 'Standard', 67: 'Extra', 68: 'Standard', 69: 'Standard', 70: 'Extra', 71: 'Standard', 72: 'Extra', 73: 'Standard', 74: 'Standard', 75: 'Standard', 76: 'Standard', 77: 'Standard', 78: 'Standard', 79: 'Standard', 80: 'Standard', 81: 'Standard', 82: 'Standard', 83: 'Standard', 84: 'Standard', 85: 'Standard', 86: 'Standard', 87: 'Standard', 88: 'Standard', 89: 'Extra', 90: 'Extra', 91: 'Standard', 92: 'Extra', 93: 'Standard', 94: 'Standard', 95: 'Standard', 96: 'Standard', 97: 'Extra', 98: 'Standard', 99: 'Standard', 100: 'Standard', 101: 'Standard', 102: 'Standard', 103: 'Standard', 104: 'Standard', 105: 'Standard', 106: 'Standard', 107: 'Standard', 108: 'Standard', 109: 'Standard', 110: 'Standard', 111: 'Extra', 112: 'Standard', 113: 'Extra', 114: 'Standard', 115: 'Extra', 116: 'Standard', 117: 'Standard', 118: 'Extra', 119: 'Standard', 120: 'Standard', 121: 'Standard', 122: 'Standard', 123: 'Standard', 124: 'Extra', 125: 'Standard', 126: 'Standard', 127: 'Standard', 128: 'Standard', 129: 'Standard', 130: 'Extra', 131: 'Standard', 132: 'Standard', 133: 'Standard', 134: 'Standard', 135: 'Standard', 136: 'Standard', 137: 'Standard', 138: 'Standard', 139: 'Extra', 140: 'Standard', 141: 'Standard', 142: 'Standard', 143: 'Standard', 144: 'Standard', 145: 'Standard', 146: 'Standard', 147: 'Standard', 148: 'Standard', 149: 'Standard', 150: 'Extra', 151: 'Standard', 152: 'Standard', 153: 'Standard', 154: 'Extra', 155: 'Standard', 156: 'Extra', 157: 'Extra', 158: 'Standard', 159: 'Standard', 160: 'Standard', 161: 'Standard', 162: 'Standard', 163: 'Extra', 164: 'Standard', 165: 'Standard', 166: 'Extra', 167: 'Standard', 168: 'Standard', 169: 'Standard', 170: 'Standard', 171: 'Standard', 172: 'Standard', 173: 'Standard', 174: 'Standard', 175: 'Standard', 176: 'Standard', 177: 'Standard', 178: 'Standard', 179: 'Standard', 180: 'Standard', 181: 'Standard', 182: 'Standard', 183: 'Standard', 184: 'Standard', 185: 'Standard', 186: 'Standard', 187: 'Standard', 188: 'Standard', 189: 'Standard', 190: 'Standard', 191: 'Standard', 192: 'Standard', 193: 'Standard', 194: 'Standard', 195: 'Standard', 196: 'Standard', 197: 'Standard', 198: 'Standard', 199: 'Standard', 200: 'Standard', 201: 'Standard', 202: 'Standard', 203: 'Standard', 204: 'Standard', 205: 'Standard', 206: 'Standard', 207: 'Standard', 208: 'Standard', 209: 'Standard', 210: 'Standard', 211: 'Extra', 212: 'Standard', 213: 'Standard', 214: 'Standard', 215: 'Standard', 216: 'Standard', 217: 'Standard', 218: 'Standard', 219: 'Standard', 220: 'Standard', 221: 'Standard', 222: 'Standard', 223: 'Standard', 224: 'Standard', 225: 'Standard', 226: 'Standard', 227: 'Standard', 228: 'Standard', 229: 'Standard', 230: 'Standard', 231: 'Standard', 232: 'Standard', 233: 'Standard', 234: 'Standard', 235: 'Standard', 236: 'Standard', 237: 'Standard', 238: 'Standard', 239: 'Standard', 240: 'Standard', 241: 'Standard', 242: 'Standard', 243: 'Standard', 244: 'Standard', 245: 'Standard', 246: 'Standard', 247: 'Extra', 248: 'Standard', 249: 'Standard', 250: 'Standard', 251: 'Extra', 252: 'Extra', 253: 'Standard', 254: 'Extra', 255: 'Extra', 256: 'Extra', 257: 'Extra', 258: 'Extra', 259: 'Extra', 260: 'Extra', 261: 'Extra', 262: 'Extra', 263: 'Standard', 264: 'Extra', 265: 'Standard', 266: 'Extra', 267: 'Extra', 268: 'Standard', 269: 'Standard', 270: 'Extra', 271: 'Extra', 272: 'Extra', 273: 'Standard', 274: 'Extra', 275: 'Standard', 276: 'Extra', 277: 'Standard', 278: 'Standard', 279: 'Standard', 280: 'Standard', 281: 'Standard', 282: 'Standard', 283: 'Standard', 284: 'Extra', 285: 'Extra', 286: 'Standard', 287: 'Standard', 288: 'Extra', 289: 'Standard', 290: 'Standard', 291: 'Extra', 292: 'Extra', 293: 'Extra', 294: 'Extra', 295: 'Standard', 296: 'Standard', 297: 'Extra', 298: 'Extra', 299: 'Standard', 300: 'Standard', 301: 'Extra', 302: 'Standard', 303: 'Standard', 304: 'Standard', 305: 'Standard', 306: 'Standard', 307: 'Extra', 308: 'Standard', 309: 'Standard', 310: 'Standard', 311: 'Extra', 312: 'Extra', 313: 'Extra', 314: 'Standard', 315: 'Standard', 316: 'Standard', 317: 'Extra', 318: 'Standard', 319: 'Extra', 320: 'Standard', 321: 'Extra', 322: 'Standard', 323: 'Extra', 324: 'Standard', 325: 'Extra', 326: 'Standard', 327: 'Standard', 328: 'Standard', 329: 'Extra', 330: 'Standard', 331: 'Standard', 332: 'Standard', 333: 'Standard', 334: 'Standard', 335: 'Extra', 336: 'Standard', 337: 'Standard', 338: 'Standard', 339: 'Extra', 340: 'Extra', 341: 'Extra', 342: 'Standard', 343: 'Standard', 344: 'Extra', 345: 'Standard', 346: 'Extra', 347: 'Standard', 348: 'Extra', 349: 'Standard', 350: 'Extra', 351: 'Standard', 352: 'Standard', 353: 'Standard', 354: 'Standard', 355: 'Standard', 356: 'Standard', 357: 'Standard', 358: 'Standard', 359: 'Standard', 360: 'Standard', 361: 'Standard', 362: 'Standard', 363: 'Extra', 364: 'Standard', 365: 'Standard', 366: 'Standard', 367: 'Extra', 368: 'Standard', 369: 'Standard', 370: 'Standard', 371: 'Extra', 372: 'Standard', 373: 'Standard', 374: 'Standard', 375: 'Standard', 376: 'Standard', 377: 'Standard', 378: 'Standard', 379: 'Extra', 380: 'Standard', 381: 'Standard', 382: 'Standard', 383: 'Extra', 384: 'Standard', 385: 'Standard', 386: 'Standard', 387: 'Standard', 388: 'Standard', 389: 'Standard', 390: 'Standard', 391: 'Standard', 392: 'Standard', 393: 'Standard', 394: 'Standard', 395: 'Standard', 396: 'Standard', 397: 'Standard', 398: 'Standard', 399: 'Extra', 400: 'Standard', 401: 'Standard', 402: 'Standard', 403: 'Standard', 404: 'Standard', 405: 'Standard', 406: 'Standard', 407: 'Standard', 408: 'Standard', 409: 'Extra', 410: 'Standard', 411: 'Standard', 412: 'Standard', 413: 'Standard', 414: 'Standard', 415: 'Standard', 416: 'Standard', 417: 'Standard', 418: 'Extra', 419: 'Standard', 420: 'Standard', 421: 'Standard', 422: 'Standard', 423: 'Standard', 424: 'Standard', 425: 'Standard', 426: 'Standard', 427: 'Standard', 428: 'Standard', 429: 'Standard', 430: 'Standard', 431: 'Standard', 432: 'Standard', 433: 'Extra', 434: 'Standard', 435: 'Standard', 436: 'Standard', 437: 'Standard', 438: 'Standard', 439: 'Standard', 440: 'Standard', 441: 'Standard', 442: 'Standard', 443: 'Standard', 444: 'Standard', 445: 'Standard', 446: 'Standard', 447: 'Standard', 448: 'Standard', 449: 'Standard', 450: 'Standard', 451: 'Standard', 452: 'Standard', 453: 'Standard', 454: 'Standard', 455: 'Standard', 456: 'Standard', 457: 'Standard', 458: 'Extra', 459: 'Extra', 460: 'Extra', 461: 'Standard', 462: 'Standard', 463: 'Standard', 464: 'Standard', 465: 'Standard', 466: 'Standard', 467: 'Standard', 468: 'Standard', 469: 'Standard', 470: 'Standard', 471: 'Extra', 472: 'Standard', 473: 'Standard', 474: 'Standard', 475: 'Standard', 476: 'Standard', 477: 'Extra', 478: 'Standard', 479: 'Standard', 480: 'Standard', 481: 'Standard', 482: 'Standard', 483: 'Standard', 484: 'Standard', 485: 'Standard', 486: 'Standard', 487: 'Standard', 488: 'Extra', 489: 'Standard', 490: 'Standard', 491: 'Standard', 492: 'Standard', 493: 'Standard', 494: 'Standard', 495: 'Standard', 496: 'Standard', 497: 'Standard', 498: 'Standard', 499: 'Extra', 500: 'Standard', 501: 'Standard', 502: 'Standard', 503: 'Standard', 504: 'Extra', 505: 'Standard', 506: 'Extra', 507: 'Standard', 508: 'Standard', 509: 'Standard', 510: 'Standard', 511: 'Extra', 512: 'Standard', 513: 'Standard', 514: 'Standard', 515: 'Extra', 516: 'Standard', 517: 'Standard', 518: 'Standard', 519: 'Extra', 520: 'Extra', 521: 'Standard', 522: 'Standard', 523: 'Standard', 524: 'Extra', 525: 'Extra', 526: 'Extra', 527: 'Standard', 528: 'Standard', 529: 'Extra', 530: 'Extra', 531: 'Extra', 532: 'Extra', 533: 'Extra', 534: 'Standard', 535: 'Extra', 536: 'Standard', 537: 'Standard', 538: 'Standard', 539: 'Extra', 540: 'Extra', 541: 'Extra', 542: 'Extra', 543: 'Extra', 544: 'Extra', 545: 'Standard', 546: 'Extra', 547: 'Extra', 548: 'Extra', 549: 'Standard', 550: 'Extra', 551: 'Extra', 552: 'Standard', 553: 'Standard', 554: 'Extra', 555: 'Extra', 556: 'Standard', 557: 'Extra', 558: 'Extra', 559: 'Extra', 560: 'Extra', 561: 'Extra', 562: 'Extra', 563: 'Standard', 564: 'Standard', 565: 'Extra', 566: 'Extra', 567: 'Extra', 568: 'Extra', 569: 'Standard', 570: 'Standard', 571: 'Extra', 572: 'Extra', 573: 'Standard', 574: 'Extra', 575: 'Standard', 576: 'Extra', 577: 'Extra', 578: 'Extra', 579: 'Extra', 580: 'Extra', 581: 'Standard', 582: 'Extra', 583: 'Standard', 584: 'Standard', 585: 'Extra', 586: 'Standard', 587: 'Standard', 588: 'Extra', 589: 'Standard', 590: 'Standard', 591: 'Extra', 592: 'Standard', 593: 'Standard', 594: 'Standard', 595: 'Extra', 596: 'Extra', 597: 'Extra', 598: 'Standard', 599: 'Standard', 600: 'Standard', 601: 'Standard', 602: 'Extra', 603: 'Extra', 604: 'Extra', 605: 'Standard', 606: 'Standard', 607: 'Standard', 608: 'Standard', 609: 'Standard', 610: 'Extra', 611: 'Standard', 612: 'Standard', 613: 'Standard', 614: 'Standard', 615: 'Standard', 616: 'Extra', 617: 'Standard', 618: 'Standard', 619: 'Standard', 620: 'Standard', 621: 'Standard', 622: 'Extra', 623: 'Standard', 624: 'Standard', 625: 'Standard', 626: 'Extra', 627: 'Standard', 628: 'Standard', 629: 'Standard', 630: 'Extra', 631: 'Extra', 632: 'Standard', 633: 'Extra', 634: 'Standard', 635: 'Standard', 636: 'Standard', 637: 'Standard', 638: 'Standard', 639: 'Standard', 640: 'Standard', 641: 'Standard', 642: 'Standard', 643: 'Standard', 644: 'Standard', 645: 'Standard', 646: 'Extra', 647: 'Extra', 648: 'Extra', 649: 'Standard', 650: 'Standard', 651: 'Standard', 652: 'Extra', 653: 'Standard', 654: 'Standard', 655: 'Standard', 656: 'Standard', 657: 'Standard', 658: 'Standard', 659: 'Standard', 660: 'Standard', 661: 'Standard', 662: 'Standard', 663: 'Standard', 664: 'Standard', 665: 'Standard', 666: 'Standard', 667: 'Extra', 668: 'Standard', 669: 'Standard', 670: 'Standard', 671: 'Standard', 672: 'Extra', 673: 'Extra', 674: 'Standard', 675: 'Standard', 676: 'Standard', 677: 'Standard', 678: 'Standard', 679: 'Extra', 680: 'Standard', 681: 'Extra', 682: 'Standard', 683: 'Standard', 684: 'Standard', 685: 'Standard', 686: 'Standard', 687: 'Extra', 688: 'Standard', 689: 'Standard', 690: 'Standard', 691: 'Standard', 692: 'Standard', 693: 'Standard', 694: 'Standard', 695: 'Standard', 696: 'Standard', 697: 'Standard', 698: 'Standard', 699: 'Extra', 700: 'Standard', 701: 'Standard', 702: 'Standard', 703: 'Standard', 704: 'Standard', 705: 'Standard', 706: 'Standard', 707: 'Standard', 708: 'Standard', 709: 'Standard', 710: 'Standard', 711: 'Standard', 712: 'Extra', 713: 'Standard', 714: 'Standard', 715: 'Standard', 716: 'Standard', 717: 'Standard', 718: 'Standard', 719: 'Standard', 720: 'Standard', 721: 'Standard', 722: 'Extra', 723: 'Standard', 724: 'Standard', 725: 'Standard', 726: 'Standard', 727: 'Standard', 728: 'Standard', 729: 'Extra', 730: 'Standard', 731: 'Standard', 732: 'Standard', 733: 'Standard', 734: 'Standard', 735: 'Standard', 736: 'Standard', 737: 'Standard', 738: 'Standard', 739: 'Standard', 740: 'Standard', 741: 'Standard', 742: 'Standard', 743: 'Standard', 744: 'Extra', 745: 'Standard', 746: 'Standard', 747: 'Standard', 748: 'Standard', 749: 'Standard', 750: 'Standard', 751: 'Standard', 752: 'Standard', 753: 'Standard', 754: 'Standard', 755: 'Standard', 756: 'Extra', 757: 'Standard', 758: 'Standard', 759: 'Standard', 760: 'Extra', 761: 'Standard', 762: 'Standard', 763: 'Standard', 764: 'Standard', 765: 'Standard', 766: 'Standard', 767: 'Standard', 768: 'Standard', 769: 'Standard', 770: 'Standard', 771: 'Standard', 772: 'Extra', 773: 'Extra', 774: 'Standard', 775: 'Standard', 776: 'Standard', 777: 'Extra', 778: 'Standard'}
}
I'm trying to visualize as simple as possible the overall advantage of Extra vs Standard (I.E: 'What is the edge of Extra over Standard?)
df[['views_per_day', 'status']].groupby('status').quantile(0.85).plot.bar()
What about using a boxplot? (eventually with a log scale):
import seaborn as sns
ax = sns.boxplot(data=df, x='status', y='views_per_day')
ax.set_yscale("log")
output:
Or a violinplot:
ax = sns.violinplot(data=df, x='status', y='views_per_day')
Related
Calculation percentage and plot using pivot-table
I need to plot a percentage graphic with a pivot table in pandas do you have any ideas? how I can calculate the percentage? thanks for your orientation! This the code that I have : df.pivot_table(index='obito', values=['asma', 'cardiopatia','diabetes','doenca_renal','obesidade']).T.plot(kind ='bar' , stacked = True) This part of the dataframe that I have: {'nome_munic': {66: 'Ferraz de Vasconcelos', 97: 'São Paulo', 100: 'São José dos Campos', 207: 'Mauá', 249: 'Cajamar', 258: 'Votuporanga', 285: 'Ferraz de Vasconcelos', 290: 'São Paulo', 345: 'São Pedro', 378: 'São Paulo'}, 'codigo_ibge': {66: 3515707, 97: 3550308, 100: 3549904, 207: 3529401, 249: 3509205, 258: 3557105, 285: 3515707, 290: 3550308, 345: 3550407, 378: 3550308}, 'idade': {66: 86, 97: 62, 100: 58, 207: 54, 249: 62, 258: 37, 285: 54, 290: 71, 345: 79, 378: 61}, 'sexo': {66: 0, 97: 0, 100: 0, 207: 1, 249: 0, 258: 1, 285: 0, 290: 0, 345: 0, 378: 0}, 'obito': {66: 1, 97: 0, 100: 0, 207: 1, 249: 1, 258: 1, 285: 0, 290: 1, 345: 1, 378: 0}, 'asma': {66: 0, 97: 0, 100: 0, 207: 1, 249: 0, 258: 0, 285: 0, 290: 0, 345: 0, 378: 0}, 'cardiopatia': {66: 1, 97: 0, 100: 1, 207: 1, 249: 1, 258: 0, 285: 1, 290: 1, 345: 0, 378: 0}, 'diabetes': {66: 1, 97: 1, 100: 0, 207: 0, 249: 1, 258: 1, 285: 0, 290: 0, 345: 1, 378: 0}, 'doenca_hematologica': {66: 0, 97: 0, 100: 0, 207: 0, 249: 0, 258: 0, 285: 0, 290: 0, 345: 0, 378: 0}, 'doenca_hepatica': {66: 0, 97: 0, 100: 0, 207: 0, 249: 0, 258: 0, 285: 0, 290: 0, 345: 0, 378: 0}, 'doenca_neurologica': {66: 0, 97: 0, 100: 0, 207: 0, 249: 0, 258: 0, 285: 0, 290: 1, 345: 0, 378: 0}, 'doenca_renal': {66: 0, 97: 0, 100: 0, 207: 0, 249: 0, 258: 0, 285: 0, 290: 0, 345: 0, 378: 0}, 'imunodepressao': {66: 0, 97: 0, 100: 1, 207: 0, 249: 0, 258: 0, 285: 0, 290: 0, 345: 0, 378: 0}, 'obesidade': {66: 0, 97: 0, 100: 0, 207: 0, 249: 1, 258: 1, 285: 0, 290: 0, 345: 0, 378: 0}, 'outros_fatores_de_risco': {66: 0, 97: 0, 100: 1, 207: 0, 249: 0, 258: 0, 285: 0, 290: 0, 345: 0, 378: 1}, 'pneumopatia': {66: 0, 97: 1, 100: 0, 207: 0, 249: 0, 258: 0, 285: 0, 290: 0, 345: 0, 378: 0}, 'puerpera': {66: 0, 97: 0, 100: 0, 207: 0, 249: 0, 258: 0, 285: 0, 290: 0, 345: 0, 378: 0}, 'sindrome_de_down': {66: 0, 97: 0, 100: 0, 207: 0, 249: 0, 258: 0, 285: 0, 290: 0, 345: 0, 378: 0}} Thanks for your support.
The default aggfunc is np.mean however it doesn’t compute the average per column or something like that, it computes the average of cells. In short it’s for every case the number of 1 divided by the number of 1 + the number of 0. This makes sense sometimes, but not for your data. >>> df[['asma', 'cardiopatia','diabetes','doenca_renal','obesidade', 'obito']] asma cardiopatia diabetes doenca_renal obesidade obito 66 0 1 1 0 0 1 97 0 0 1 0 0 0 100 0 1 0 0 0 0 207 1 1 0 0 0 1 249 0 1 1 0 1 1 258 0 0 1 0 1 1 285 0 1 0 0 0 0 290 0 1 0 0 0 1 345 0 0 1 0 0 1 378 0 0 0 0 0 0 >>> df.pivot_table(index='obito', values=['asma', 'cardiopatia','diabetes','doenca_renal','obesidade']) asma cardiopatia diabetes doenca_renal obesidade obito 0 0.000000 0.500000 0.250000 0 0.000000 1 0.166667 0.666667 0.666667 0 0.333333 Instead you probably want to count the total of patients per cell, then divide by column totals: >>> counts = df.pivot_table(index='obito', values=['asma', 'cardiopatia','diabetes','doenca_renal','obesidade'], aggfunc=np.sum) >>> counts / counts.sum() asma cardiopatia diabetes doenca_renal obesidade obito 0 0.0 0.333333 0.2 NaN 0.0 1 1.0 0.666667 0.8 NaN 1.0 Note how every column now sums to 1. doenca_renal is NaN because it has no patients at all in the sample, so the percentage is not defined. If you only want to plot the percentages that have obito=1, then you can do this: >>> from matplotlib import ticker >>> ax = (counts / counts.sum()).loc[1].plot.bar(rot=0) >>> ax.yaxis.set_major_formatter(ticker.PercentFormatter(xmax=1)) If you want to annotate the percentages on the bar, see this other question
Matching Buy Sell entries from two dataframes and creating a new one. Python 3.8 / W10
Python / Pandas. Matching Buy and Sell entries row by row. BuyDF and SellDF are obtained from one excel file and sorted as per ascending Time (column L). The image shows how the matching has to be done. Match Buy and Sell entries by Name following first in first out method. Take very first entry (Name AAA) from BuyDF and match with very first / Top most entry (Name AAA) from SellDF and move the matching row from SellDF in front of corrosponding row of BuyDF and delete the row Sell DF. Go back to BuyDF second entry and match SellDF entry and move the matching row from SellDF and move the matching row from SellDF in front of corrosponding row of BuyDF and the row is deleted from Sell DF ...... and so on. For names which do not match leave the matching rows Blank. The ascending order (Time / Column L) should not be changed to maintain first in first out. Tried using merge but didn't work for me. How to proceed ? BuyDF {'Date': {0: '2019-04-01', 1: '2019-04-01', 2: '2019-04-01', 3: '2019-04-01', 4: '2019-04-02', 5: '2019-04-02', 6: '2019-04-02', 7: '2019-04-02', 8: '2019-04-05'}, 'Name': {0: 'AAA', 1: 'AAA', 2: 'AAA', 3: 'AAA', 4: 'BBB', 5: 'CCC', 6: 'CCC', 7: 'BBB', 8: 'AAA'}, 'Ref': {0: 1, 1: 1, 2: 1, 3: 1, 4: 5, 5: 7, 6: 7, 7: 6, 8: 1}, 'Seg': {0: 'S', 1: 'S', 2: 'S', 3: 'S', 4: 'L', 5: 'XL', 6: 'XL', 7: 'L', 8: 'S'}, 'Trans': {0: 'buy', 1: 'buy', 2: 'buy', 3: 'buy', 4: 'buy', 5: 'buy', 6: 'buy', 7: 'buy', 8: 'buy'}, 'Qty': {0: 1, 1: 1, 2: 1, 3: 1, 4: 1, 5: 1, 6: 1, 7: 1, 8: 1}, 'Price': {0: 225, 1: 225, 2: 225, 3: 225, 4: 210, 5: 210, 6: 210, 7: 210, 8: 225}, 'Order ID': {0: 8249, 1: 111, 2: 654, 3: 111, 4: 888, 5: 444, 6: 444, 7: 888, 8: 111}, 'Trade ID': {0: 1010, 1: 1010, 2: 1010, 3: 1010, 4: 4645, 5: 132, 6: 132, 7: 4700, 8: 1010}, 'Time': {0: '2019-04-01 11:05:18', 1: '2019-04-01 13:05:18', 2: '2019-04-01 13:05:18', 3: '2019-04-01 13:05:59', 4: '2019-04-02 13:20:05', 5: '2019-04-02 13:35:02', 6: '2019-04-02 13:35:02', 7: '2019-04-02 14:20:12', 8: '2019-04-05 13:05:18'}} SellDF {'Date': {5: '2019-04-01', 6: '2019-04-02', 7: '2019-04-02', 8: '2019-04-02', 13: '2019-04-03', 14: '2019-04-05', 15: '2019-04-05'}, 'Name': {5: 'AAA', 6: 'BBB', 7: 'BBB', 8: 'BBB', 13: 'DDD', 14: 'AAA', 15: 'AAA'}, 'Ref': {5: 3, 6: 2, 7: 2, 8: 2, 13: 8, 14: 4, 15: 4}, 'Seg': {5: 'L', 6: 'X', 7: 'X', 8: 'X', 13: 'XS', 14: 'L', 15: 'L'}, 'Trans': {5: 'sell', 6: 'sell', 7: 'sell', 8: 'sell', 13: 'sell', 14: 'sell', 15: 'sell'}, 'Qty': {5: 1, 6: 1, 7: 1, 8: 1, 13: 1, 14: 1, 15: 1}, 'Price': {5: 210, 6: 210, 7: 210, 8: 210, 13: 210, 14: 210, 15: 210}, 'Order ID': {5: 555, 6: 222, 7: 222, 8: 222, 13: 999, 14: 555, 15: 555}, 'Trade ID': {5: 1640, 6: 1532, 7: 1532, 8: 1532, 13: 14623, 14: 1645, 15: 1645}, 'Time': {5: '2019-04-01 14:13:40', 6: '2019-04-02 13:10:32', 7: '2019-04-02 13:10:32', 8: '2019-04-02 13:10:32', 13: '2019-04-03 15:25:50', 14: '2019-04-05 14:41:45', 15: '2019-04-05 14:41:45'}} Image posted for ease of understanding.
summing up values in dictionary
I am working with networkX which is a graph based library in python. I have truncated data here because it is just a list of dictionaries. I want to sum up the number of triangles in a graph. import networkx as nx for i in graphT: print(nx.triangles(i)) This generates {0: 1, 1: 0, 2: 0, 3: 1, 4: 0, 5: 0, 6: 0, 7: 0, 8: 0, 9: 0, 10: 1, 11: 0, 12: 2, 13: 0, 14: 2, 15: 1, 16: 1, 17: 0, 18: 0, 19: 1, 20: 0, 21: 0, 22: 0, 23: 0, 24: 0, 25: 5, 26: 1, 27: 0, 28: 0, 29: 1, 30: 0, 31: 0, 32: 0, 33: 4, 34: 1, 35: 3, 36: 1, 37: 1, 38: 2, 39: 1} {0: 1, 1: 0, 2: 0, 3: 1, 4: 2, 5: 0, 6: 0, 7: 0, 8: 0, 9: 2, 10: 2, 11: 0, 12: 2, 13: 2, 14: 3, 15: 2, 16: 1, 17: 0, 18: 1, 19: 0, 20: 0, 21: 0, 22: 0, 23: 0, 24: 0, 25: 2, 26: 2, 27: 0, 28: 0, 29: 1, 30: 0, 31: 0, 32: 0, 33: 2, 34: 0, 35: 2, 36: 1, 37: 1, 38: 1, 39: 2} {0: 1, 1: 1, 2: 0, 3: 2, 4: 0, 5: 0, 6: 0, 7: 0, 8: 0, 9: 0, 10: 2, 11: 0, 12: 4, 13: 0, 14: 3, 15: 4, 16: 1, 17: 1, 18: 0, 19: 0, 20: 0, 21: 0, 22: 1, 23: 0, 24: 0, 25: 3, 26: 2, 27: 0, 28: 0, 29: 1, 30: 0, 31: 0, 32: 0, 33: 1, 34: 1, 35: 2, 36: 1, 37: 1, 38: 2, 39: 2} ...... Now with that, I want to sum the values for which for i in graphT: #print(nx.triangles(i)) for k, v in nx.triangles(i).items(): #print(i.number_of_edges(), v) #print(jt.append(v)) vi= v print(k, vi) break which generates tuple of for key '0'. I have truncated data here with break statement. (0, 1) (0, 1) (0, 1) (0, 1) (0, 1) (0, 1) (0, 1) (0, 5) (0, 2) (0, 4) (0, 3) (0, 5) (0, 2) (0, 3) (0, 4) (0, 1) (0, 4) (0, 1) (0, 8) (0, 5) (0, 2) (0, 4) (0, 3) (0, 5) (0, 6) (0, 3) (0, 3) (0, 11) (0, 7) (0, 18) (0, 9) (0, 8) (0, 4) (0, 12) (0, 22) (0, 14) (0, 23) (0, 18) (0, 2) (0, 41) (0, 8) (0, 29) (0, 13) (0, 12) (0, 53) (0, 12) How would I sum up values on this this tuple which is second element? If I use sum(v) or sum(vi) I get TypeError: 'int' object is not iterable. This gives me solution: j= [(sum(n for _, n in nx.triangles(i).items()), i.number_of_edges()) for i in graphT]
You can access all of the values of a dictionary with values. Then sum those. So for this case: import networkx as nx G = nx.fast_gnp_random_graph(1000,0.05) triangle_counts = nx.triangles(G) triangle_sum = sum(triangle_counts.values()) number_of_triangles = triangle_sum/3 print(number_of_triangles) > 20444.0 Note that each triangle is counted once per node, so I've divided by 3.
C stack usage error with SQL in R notebook
Problem I just started using R notebooks and was impressed with being able to use SQL chunks. However I have run into a bizarre problem. My code within the notebook looks something like the following ```{r} library(RSQLite) library(plyr) library(Matrix) ``` ```{r} sessionInfo() ``` ```{r} dbName = '/home/my_db.db' db <- dbConnect(SQLite(), dbname=dbName) ``` ```{sql connection=db, max.print=10} SELECT * FROM EVENTS_ID ``` The error I get is Error: C stack usage 7969396 is too close to the limit Failed to execute SQL chunk Now I have a further SQL query further in the notebook that when executed gives a similar error with a different number, Error: C stack usage 7969604 is too close to the limit Failed to execute SQL chunk The most strange thing about this however is that the code was running fine previously and I've made no changes that I can think of. Attempted Solutions/Debugging 1) Restarted computer. Still get the same errors. 2) Changed the code to the following to rule out database table error ```{sql connection=db} SELECT 1 ``` Still got the same error. Current Workaround I can workaround the issue by doing everything in R instead of the SQL chunk i.e. ```{r} query <- gsub(pattern='\\s',replacement=" ",x="SELECT * FROM EVENTS_ID LIMIT 10") dbGetQuery(db, query) ``` This works but I would like to use the SQL chunks if possible. Further Info When running traceback() after the error I get the following which may suggest there is some kind of as.vector recursion error 936: as.vector(x, mode) 935: as.vector(x, mode) 934: as.vector(x, mode) 933: as.vector(x, mode) 932: as.vector(x, mode) 931: as.vector(x, mode) 930: as.vector(x, mode) 929: as.vector(x, mode) 928: as.vector(x, mode) 927: as.vector(x, mode) 926: as.vector(x, mode) 925: as.vector(x, mode) 924: as.vector(x, mode) 923: as.vector(x, mode) 922: as.vector(x, mode) 921: as.vector(x, mode) 920: as.vector(x, mode) 919: as.vector(x, mode) 918: as.vector(x, mode) 917: as.vector(x, mode) 916: as.vector(x, mode) 915: as.vector(x, mode) 914: as.vector(x, mode) 913: as.vector(x, mode) 912: as.vector(x, mode) 911: as.vector(x, mode) 910: as.vector(x, mode) 909: as.vector(x, mode) 908: as.vector(x, mode) 907: as.vector(x, mode) 906: as.vector(x, mode) 905: as.vector(x, mode) 904: as.vector(x, mode) 903: as.vector(x, mode) 902: as.vector(x, mode) 901: as.vector(x, mode) 900: as.vector(x, mode) 899: as.vector(x, mode) 898: as.vector(x, mode) 897: as.vector(x, mode) 896: as.vector(x, mode) 895: as.vector(x, mode) 894: as.vector(x, mode) 893: as.vector(x, mode) 892: as.vector(x, mode) 891: as.vector(x, mode) 890: as.vector(x, mode) 889: as.vector(x, mode) 888: as.vector(x, mode) 887: as.vector(x, mode) 886: as.vector(x, mode) 885: as.vector(x, mode) 884: as.vector(x, mode) 883: as.vector(x, mode) 882: as.vector(x, mode) 881: as.vector(x, mode) 880: as.vector(x, mode) 879: as.vector(x, mode) 878: as.vector(x, mode) 877: as.vector(x, mode) 876: as.vector(x, mode) 875: as.vector(x, mode) 874: as.vector(x, mode) 873: as.vector(x, mode) 872: as.vector(x, mode) 871: as.vector(x, mode) 870: as.vector(x, mode) 869: as.vector(x, mode) 868: as.vector(x, mode) 867: as.vector(x, mode) 866: as.vector(x, mode) 865: as.vector(x, mode) 864: as.vector(x, mode) 863: as.vector(x, mode) 862: as.vector(x, mode) 861: as.vector(x, mode) 860: as.vector(x, mode) 859: as.vector(x, mode) 858: as.vector(x, mode) 857: as.vector(x, mode) 856: as.vector(x, mode) 855: as.vector(x, mode) 854: as.vector(x, mode) 853: as.vector(x, mode) 852: as.vector(x, mode) 851: as.vector(x, mode) 850: as.vector(x, mode) 849: as.vector(x, mode) 848: as.vector(x, mode) 847: as.vector(x, mode) 846: as.vector(x, mode) 845: as.vector(x, mode) 844: as.vector(x, mode) 843: as.vector(x, mode) 842: as.vector(x, mode) 841: as.vector(x, mode) 840: as.vector(x, mode) 839: as.vector(x, mode) 838: as.vector(x, mode) 837: as.vector(x, mode) 836: as.vector(x, mode) 835: as.vector(x, mode) 834: as.vector(x, mode) 833: as.vector(x, mode) 832: as.vector(x, mode) 831: as.vector(x, mode) 830: as.vector(x, mode) 829: as.vector(x, mode) 828: as.vector(x, mode) 827: as.vector(x, mode) 826: as.vector(x, mode) 825: as.vector(x, mode) 824: as.vector(x, mode) 823: as.vector(x, mode) 822: as.vector(x, mode) 821: as.vector(x, mode) 820: as.vector(x, mode) 819: as.vector(x, mode) 818: as.vector(x, mode) 817: as.vector(x, mode) 816: as.vector(x, mode) 815: as.vector(x, mode) 814: as.vector(x, mode) 813: as.vector(x, mode) 812: as.vector(x, mode) 811: as.vector(x, mode) 810: as.vector(x, mode) 809: as.vector(x, mode) 808: as.vector(x, mode) 807: as.vector(x, mode) 806: as.vector(x, mode) 805: as.vector(x, mode) 804: as.vector(x, mode) 803: as.vector(x, mode) 802: as.vector(x, mode) 801: as.vector(x, mode) 800: as.vector(x, mode) 799: as.vector(x, mode) 798: as.vector(x, mode) 797: as.vector(x, mode) 796: as.vector(x, mode) 795: as.vector(x, mode) 794: as.vector(x, mode) 793: as.vector(x, mode) 792: as.vector(x, mode) 791: as.vector(x, mode) 790: as.vector(x, mode) 789: as.vector(x, mode) 788: as.vector(x, mode) 787: as.vector(x, mode) 786: as.vector(x, mode) 785: as.vector(x, mode) 784: as.vector(x, mode) 783: as.vector(x, mode) 782: as.vector(x, mode) 781: as.vector(x, mode) 780: as.vector(x, mode) 779: as.vector(x, mode) 778: as.vector(x, mode) 777: as.vector(x, mode) 776: as.vector(x, mode) 775: as.vector(x, mode) 774: as.vector(x, mode) 773: as.vector(x, mode) 772: as.vector(x, mode) 771: as.vector(x, mode) 770: as.vector(x, mode) 769: as.vector(x, mode) 768: as.vector(x, mode) 767: as.vector(x, mode) 766: as.vector(x, mode) 765: as.vector(x, mode) 764: as.vector(x, mode) 763: as.vector(x, mode) 762: as.vector(x, mode) 761: as.vector(x, mode) 760: as.vector(x, mode) 759: as.vector(x, mode) 758: as.vector(x, mode) 757: as.vector(x, mode) 756: as.vector(x, mode) 755: as.vector(x, mode) 754: as.vector(x, mode) 753: as.vector(x, mode) 752: as.vector(x, mode) 751: as.vector(x, mode) 750: as.vector(x, mode) 749: as.vector(x, mode) 748: as.vector(x, mode) 747: as.vector(x, mode) 746: as.vector(x, mode) 745: as.vector(x, mode) 744: as.vector(x, mode) 743: as.vector(x, mode) 742: as.vector(x, mode) 741: as.vector(x, mode) 740: as.vector(x, mode) 739: as.vector(x, mode) 738: as.vector(x, mode) 737: as.vector(x, mode) 736: as.vector(x, mode) 735: as.vector(x, mode) 734: as.vector(x, mode) 733: as.vector(x, mode) 732: as.vector(x, mode) 731: as.vector(x, mode) 730: as.vector(x, mode) 729: as.vector(x, mode) 728: as.vector(x, mode) 727: as.vector(x, mode) 726: as.vector(x, mode) 725: as.vector(x, mode) 724: as.vector(x, mode) 723: as.vector(x, mode) 722: as.vector(x, mode) 721: as.vector(x, mode) 720: as.vector(x, mode) 719: as.vector(x, mode) 718: as.vector(x, mode) 717: as.vector(x, mode) 716: as.vector(x, mode) 715: as.vector(x, mode) 714: as.vector(x, mode) 713: as.vector(x, mode) 712: as.vector(x, mode) 711: as.vector(x, mode) 710: as.vector(x, mode) 709: as.vector(x, mode) 708: as.vector(x, mode) 707: as.vector(x, mode) 706: as.vector(x, mode) 705: as.vector(x, mode) 704: as.vector(x, mode) 703: as.vector(x, mode) 702: as.vector(x, mode) 701: as.vector(x, mode) 700: as.vector(x, mode) 699: as.vector(x, mode) 698: as.vector(x, mode) 697: as.vector(x, mode) 696: as.vector(x, mode) 695: as.vector(x, mode) 694: as.vector(x, mode) 693: as.vector(x, mode) 692: as.vector(x, mode) 691: as.vector(x, mode) 690: as.vector(x, mode) 689: as.vector(x, mode) 688: as.vector(x, mode) 687: as.vector(x, mode) 686: as.vector(x, mode) 685: as.vector(x, mode) 684: as.vector(x, mode) 683: as.vector(x, mode) 682: as.vector(x, mode) 681: as.vector(x, mode) 680: as.vector(x, mode) 679: as.vector(x, mode) 678: as.vector(x, mode) 677: as.vector(x, mode) 676: as.vector(x, mode) 675: as.vector(x, mode) 674: as.vector(x, mode) 673: as.vector(x, mode) 672: as.vector(x, mode) 671: as.vector(x, mode) 670: as.vector(x, mode) 669: as.vector(x, mode) 668: as.vector(x, mode) 667: as.vector(x, mode) 666: as.vector(x, mode) 665: as.vector(x, mode) 664: as.vector(x, mode) 663: as.vector(x, mode) 662: as.vector(x, mode) 661: as.vector(x, mode) 660: as.vector(x, mode) 659: as.vector(x, mode) 658: as.vector(x, mode) 657: as.vector(x, mode) 656: as.vector(x, mode) 655: as.vector(x, mode) 654: as.vector(x, mode) 653: as.vector(x, mode) 652: as.vector(x, mode) 651: as.vector(x, mode) 650: as.vector(x, mode) 649: as.vector(x, mode) 648: as.vector(x, mode) 647: as.vector(x, mode) 646: as.vector(x, mode) 645: as.vector(x, mode) 644: as.vector(x, mode) 643: as.vector(x, mode) 642: as.vector(x, mode) 641: as.vector(x, mode) 640: as.vector(x, mode) 639: as.vector(x, mode) 638: as.vector(x, mode) 637: as.vector(x, mode) 636: as.vector(x, mode) 635: as.vector(x, mode) 634: as.vector(x, mode) 633: as.vector(x, mode) 632: as.vector(x, mode) 631: as.vector(x, mode) 630: as.vector(x, mode) 629: as.vector(x, mode) 628: as.vector(x, mode) 627: as.vector(x, mode) 626: as.vector(x, mode) 625: as.vector(x, mode) 624: as.vector(x, mode) 623: as.vector(x, mode) 622: as.vector(x, mode) 621: as.vector(x, mode) 620: as.vector(x, mode) 619: as.vector(x, mode) 618: as.vector(x, mode) 617: as.vector(x, mode) 616: as.vector(x, mode) 615: as.vector(x, mode) 614: as.vector(x, mode) 613: as.vector(x, mode) 612: as.vector(x, mode) 611: as.vector(x, mode) 610: as.vector(x, mode) 609: as.vector(x, mode) 608: as.vector(x, mode) 607: as.vector(x, mode) 606: as.vector(x, mode) 605: as.vector(x, mode) 604: as.vector(x, mode) 603: as.vector(x, mode) 602: as.vector(x, mode) 601: as.vector(x, mode) 600: as.vector(x, mode) 599: as.vector(x, mode) 598: as.vector(x, mode) 597: as.vector(x, mode) 596: as.vector(x, mode) 595: as.vector(x, mode) 594: as.vector(x, mode) 593: as.vector(x, mode) 592: as.vector(x, mode) 591: as.vector(x, mode) 590: as.vector(x, mode) 589: as.vector(x, mode) 588: as.vector(x, mode) 587: as.vector(x, mode) 586: as.vector(x, mode) 585: as.vector(x, mode) 584: as.vector(x, mode) 583: as.vector(x, mode) 582: as.vector(x, mode) 581: as.vector(x, mode) 580: as.vector(x, mode) 579: as.vector(x, mode) 578: as.vector(x, mode) 577: as.vector(x, mode) 576: as.vector(x, mode) 575: as.vector(x, mode) 574: as.vector(x, mode) 573: as.vector(x, mode) 572: as.vector(x, mode) 571: as.vector(x, mode) 570: as.vector(x, mode) 569: as.vector(x, mode) 568: as.vector(x, mode) 567: as.vector(x, mode) 566: as.vector(x, mode) 565: as.vector(x, mode) 564: as.vector(x, mode) 563: as.vector(x, mode) 562: as.vector(x, mode) 561: as.vector(x, mode) 560: as.vector(x, mode) 559: as.vector(x, mode) 558: as.vector(x, mode) 557: as.vector(x, mode) 556: as.vector(x, mode) 555: as.vector(x, mode) 554: as.vector(x, mode) 553: as.vector(x, mode) 552: as.vector(x, mode) 551: as.vector(x, mode) 550: as.vector(x, mode) 549: as.vector(x, mode) 548: as.vector(x, mode) 547: as.vector(x, mode) 546: as.vector(x, mode) 545: as.vector(x, mode) 544: as.vector(x, mode) 543: as.vector(x, mode) 542: as.vector(x, mode) 541: as.vector(x, mode) 540: as.vector(x, mode) 539: as.vector(x, mode) 538: as.vector(x, mode) 537: as.vector(x, mode) 536: as.vector(x, mode) 535: as.vector(x, mode) 534: as.vector(x, mode) 533: as.vector(x, mode) 532: as.vector(x, mode) 531: as.vector(x, mode) 530: as.vector(x, mode) 529: as.vector(x, mode) 528: as.vector(x, mode) 527: as.vector(x, mode) 526: as.vector(x, mode) 525: as.vector(x, mode) 524: as.vector(x, mode) 523: as.vector(x, mode) 522: as.vector(x, mode) 521: as.vector(x, mode) 520: as.vector(x, mode) 519: as.vector(x, mode) 518: as.vector(x, mode) 517: as.vector(x, mode) 516: as.vector(x, mode) 515: as.vector(x, mode) 514: as.vector(x, mode) 513: as.vector(x, mode) 512: as.vector(x, mode) 511: as.vector(x, mode) 510: as.vector(x, mode) 509: as.vector(x, mode) 508: as.vector(x, mode) 507: as.vector(x, mode) 506: as.vector(x, mode) 505: as.vector(x, mode) 504: as.vector(x, mode) 503: as.vector(x, mode) 502: as.vector(x, mode) 501: as.vector(x, mode) 500: as.vector(x, mode) 499: as.vector(x, mode) 498: as.vector(x, mode) 497: as.vector(x, mode) 496: as.vector(x, mode) 495: as.vector(x, mode) 494: as.vector(x, mode) 493: as.vector(x, mode) 492: as.vector(x, mode) 491: as.vector(x, mode) 490: as.vector(x, mode) 489: as.vector(x, mode) 488: as.vector(x, mode) 487: as.vector(x, mode) 486: as.vector(x, mode) 485: as.vector(x, mode) 484: as.vector(x, mode) 483: as.vector(x, mode) 482: as.vector(x, mode) 481: as.vector(x, mode) 480: as.vector(x, mode) 479: as.vector(x, mode) 478: as.vector(x, mode) 477: as.vector(x, mode) 476: as.vector(x, mode) 475: as.vector(x, mode) 474: as.vector(x, mode) 473: as.vector(x, mode) 472: as.vector(x, mode) 471: as.vector(x, mode) 470: as.vector(x, mode) 469: as.vector(x, mode) 468: as.vector(x, mode) 467: as.vector(x, mode) 466: as.vector(x, mode) 465: as.vector(x, mode) 464: as.vector(x, mode) 463: as.vector(x, mode) 462: as.vector(x, mode) 461: as.vector(x, mode) 460: as.vector(x, mode) 459: as.vector(x, mode) 458: as.vector(x, mode) 457: as.vector(x, mode) 456: as.vector(x, mode) 455: as.vector(x, mode) 454: as.vector(x, mode) 453: as.vector(x, mode) 452: as.vector(x, mode) 451: as.vector(x, mode) 450: as.vector(x, mode) 449: as.vector(x, mode) 448: as.vector(x, mode) 447: as.vector(x, mode) 446: as.vector(x, mode) 445: as.vector(x, mode) 444: as.vector(x, mode) 443: as.vector(x, mode) 442: as.vector(x, mode) 441: as.vector(x, mode) 440: as.vector(x, mode) 439: as.vector(x, mode) 438: as.vector(x, mode) 437: as.vector(x, mode) 436: as.vector(x, mode) 435: as.vector(x, mode) 434: as.vector(x, mode) 433: as.vector(x, mode) 432: as.vector(x, mode) 431: as.vector(x, mode) 430: as.vector(x, mode) 429: as.vector(x, mode) 428: as.vector(x, mode) 427: as.vector(x, mode) 426: as.vector(x, mode) 425: as.vector(x, mode) 424: as.vector(x, mode) 423: as.vector(x, mode) 422: as.vector(x, mode) 421: as.vector(x, mode) 420: as.vector(x, mode) 419: as.vector(x, mode) 418: as.vector(x, mode) 417: as.vector(x, mode) 416: as.vector(x, mode) 415: as.vector(x, mode) 414: as.vector(x, mode) 413: as.vector(x, mode) 412: as.vector(x, mode) 411: as.vector(x, mode) 410: as.vector(x, mode) 409: as.vector(x, mode) 408: as.vector(x, mode) 407: as.vector(x, mode) 406: as.vector(x, mode) 405: as.vector(x, mode) 404: as.vector(x, mode) 403: as.vector(x, mode) 402: as.vector(x, mode) 401: as.vector(x, mode) 400: as.vector(x, mode) 399: as.vector(x, mode) 398: as.vector(x, mode) 397: as.vector(x, mode) 396: as.vector(x, mode) 395: as.vector(x, mode) 394: as.vector(x, mode) 393: as.vector(x, mode) 392: as.vector(x, mode) 391: as.vector(x, mode) 390: as.vector(x, mode) 389: as.vector(x, mode) 388: as.vector(x, mode) 387: as.vector(x, mode) 386: as.vector(x, mode) 385: as.vector(x, mode) 384: as.vector(x, mode) 383: as.vector(x, mode) 382: as.vector(x, mode) 381: as.vector(x, mode) 380: as.vector(x, mode) 379: as.vector(x, mode) 378: as.vector(x, mode) 377: as.vector(x, mode) 376: as.vector(x, mode) 375: as.vector(x, mode) 374: as.vector(x, mode) 373: as.vector(x, mode) 372: as.vector(x, mode) 371: as.vector(x, mode) 370: as.vector(x, mode) 369: as.vector(x, mode) 368: as.vector(x, mode) 367: as.vector(x, mode) 366: as.vector(x, mode) 365: as.vector(x, mode) 364: as.vector(x, mode) 363: as.vector(x, mode) 362: as.vector(x, mode) 361: as.vector(x, mode) 360: as.vector(x, mode) 359: as.vector(x, mode) 358: as.vector(x, mode) 357: as.vector(x, mode) 356: as.vector(x, mode) 355: as.vector(x, mode) 354: as.vector(x, mode) 353: as.vector(x, mode) 352: as.vector(x, mode) 351: as.vector(x, mode) 350: as.vector(x, mode) 349: as.vector(x, mode) 348: as.vector(x, mode) 347: as.vector(x, mode) 346: as.vector(x, mode) 345: as.vector(x, mode) 344: as.vector(x, mode) 343: as.vector(x, mode) 342: as.vector(x, mode) 341: as.vector(x, mode) 340: as.vector(x, mode) 339: as.vector(x, mode) 338: as.vector(x, mode) 337: as.vector(x, mode) 336: as.vector(x, mode) 335: as.vector(x, mode) 334: as.vector(x, mode) 333: as.vector(x, mode) 332: as.vector(x, mode) 331: as.vector(x, mode) 330: as.vector(x, mode) 329: as.vector(x, mode) 328: as.vector(x, mode) 327: as.vector(x, mode) 326: as.vector(x, mode) 325: as.vector(x, mode) 324: as.vector(x, mode) 323: as.vector(x, mode) 322: as.vector(x, mode) 321: as.vector(x, mode) 320: as.vector(x, mode) 319: as.vector(x, mode) 318: as.vector(x, mode) 317: as.vector(x, mode) 316: as.vector(x, mode) 315: as.vector(x, mode) 314: as.vector(x, mode) 313: as.vector(x, mode) 312: as.vector(x, mode) 311: as.vector(x, mode) 310: as.vector(x, mode) 309: as.vector(x, mode) 308: as.vector(x, mode) 307: as.vector(x, mode) 306: as.vector(x, mode) 305: as.vector(x, mode) 304: as.vector(x, mode) 303: as.vector(x, mode) 302: as.vector(x, mode) 301: as.vector(x, mode) 300: as.vector(x, mode) 299: as.vector(x, mode) 298: as.vector(x, mode) 297: as.vector(x, mode) 296: as.vector(x, mode) 295: as.vector(x, mode) 294: as.vector(x, mode) 293: as.vector(x, mode) 292: as.vector(x, mode) 291: as.vector(x, mode) 290: as.vector(x, mode) 289: as.vector(x, mode) 288: as.vector(x, mode) 287: as.vector(x, mode) 286: as.vector(x, mode) 285: as.vector(x, mode) 284: as.vector(x, mode) 283: as.vector(x, mode) 282: as.vector(x, mode) 281: as.vector(x, mode) 280: as.vector(x, mode) 279: as.vector(x, mode) 278: as.vector(x, mode) 277: as.vector(x, mode) 276: as.vector(x, mode) 275: as.vector(x, mode) 274: as.vector(x, mode) 273: as.vector(x, mode) 272: as.vector(x, mode) 271: as.vector(x, mode) 270: as.vector(x, mode) 269: as.vector(x, mode) 268: as.vector(x, mode) 267: as.vector(x, mode) 266: as.vector(x, mode) 265: as.vector(x, mode) 264: as.vector(x, mode) 263: as.vector(x, mode) 262: as.vector(x, mode) 261: as.vector(x, mode) 260: as.vector(x, mode) 259: as.vector(x, mode) 258: as.vector(x, mode) 257: as.vector(x, mode) 256: as.vector(x, mode) 255: as.vector(x, mode) 254: as.vector(x, mode) 253: as.vector(x, mode) 252: as.vector(x, mode) 251: as.vector(x, mode) 250: as.vector(x, mode) 249: as.vector(x, mode) 248: as.vector(x, mode) 247: as.vector(x, mode) 246: as.vector(x, mode) 245: as.vector(x, mode) 244: as.vector(x, mode) 243: as.vector(x, mode) 242: as.vector(x, mode) 241: as.vector(x, mode) 240: as.vector(x, mode) 239: as.vector(x, mode) 238: as.vector(x, mode) 237: as.vector(x, mode) 236: as.vector(x, mode) 235: as.vector(x, mode) 234: as.vector(x, mode) 233: as.vector(x, mode) 232: as.vector(x, mode) 231: as.vector(x, mode) 230: as.vector(x, mode) 229: as.vector(x, mode) 228: as.vector(x, mode) 227: as.vector(x, mode) 226: as.vector(x, mode) 225: as.vector(x, mode) 224: as.vector(x, mode) 223: as.vector(x, mode) 222: as.vector(x, mode) 221: as.vector(x, mode) 220: as.vector(x, mode) 219: as.vector(x, mode) 218: as.vector(x, mode) 217: as.vector(x, mode) 216: as.vector(x, mode) 215: as.vector(x, mode) 214: as.vector(x, mode) 213: as.vector(x, mode) 212: as.vector(x, mode) 211: as.vector(x, mode) 210: as.vector(x, mode) 209: as.vector(x, mode) 208: as.vector(x, mode) 207: as.vector(x, mode) 206: as.vector(x, mode) 205: as.vector(x, mode) 204: as.vector(x, mode) 203: as.vector(x, mode) 202: as.vector(x, mode) 201: as.vector(x, mode) 200: as.vector(x, mode) 199: as.vector(x, mode) 198: as.vector(x, mode) 197: as.vector(x, mode) 196: as.vector(x, mode) 195: as.vector(x, mode) 194: as.vector(x, mode) 193: as.vector(x, mode) 192: as.vector(x, mode) 191: as.vector(x, mode) 190: as.vector(x, mode) 189: as.vector(x, mode) 188: as.vector(x, mode) 187: as.vector(x, mode) 186: as.vector(x, mode) 185: as.vector(x, mode) 184: as.vector(x, mode) 183: as.vector(x, mode) 182: as.vector(x, mode) 181: as.vector(x, mode) 180: as.vector(x, mode) 179: as.vector(x, mode) 178: as.vector(x, mode) 177: as.vector(x, mode) 176: as.vector(x, mode) 175: as.vector(x, mode) 174: as.vector(x, mode) 173: as.vector(x, mode) 172: as.vector(x, mode) 171: as.vector(x, mode) 170: as.vector(x, mode) 169: as.vector(x, mode) 168: as.vector(x, mode) 167: as.vector(x, mode) 166: as.vector(x, mode) 165: as.vector(x, mode) 164: as.vector(x, mode) 163: as.vector(x, mode) 162: as.vector(x, mode) 161: as.vector(x, mode) 160: as.vector(x, mode) 159: as.vector(x, mode) 158: as.vector(x, mode) 157: as.vector(x, mode) 156: as.vector(x, mode) 155: as.vector(x, mode) 154: as.vector(x, mode) 153: as.vector(x, mode) 152: as.vector(x, mode) 151: as.vector(x, mode) 150: as.vector(x, mode) 149: as.vector(x, mode) 148: as.vector(x, mode) 147: as.vector(x, mode) 146: as.vector(x, mode) 145: as.vector(x, mode) 144: as.vector(x, mode) 143: as.vector(x, mode) 142: as.vector(x, mode) 141: as.vector(x, mode) 140: as.vector(x, mode) 139: as.vector(x, mode) 138: as.vector(x, mode) 137: as.vector(x, mode) 136: as.vector(x, mode) 135: as.vector(x, mode) 134: as.vector(x, mode) 133: as.vector(x, mode) 132: as.vector(x, mode) 131: as.vector(x, mode) 130: as.vector(x, mode) 129: as.vector(x, mode) 128: as.vector(x, mode) 127: as.vector(x, mode) 126: as.vector(x, mode) 125: as.vector(x, mode) 124: as.vector(x, mode) 123: as.vector(x, mode) 122: as.vector(x, mode) 121: as.vector(x, mode) 120: as.vector(x, mode) 119: as.vector(x, mode) 118: as.vector(x, mode) 117: as.vector(x, mode) 116: as.vector(x, mode) 115: as.vector(x, mode) 114: as.vector(x, mode) 113: as.vector(x, mode) 112: as.vector(x, mode) 111: as.vector(x, mode) 110: as.vector(x, mode) 109: as.vector(x, mode) 108: as.vector(x, mode) 107: as.vector(x, mode) 106: as.vector(x, mode) 105: as.vector(x, mode) 104: as.vector(x, mode) 103: as.vector(x, mode) 102: as.vector(x, mode) 101: as.vector(x, mode) 100: as.vector(x, mode) 99: as.vector(x, mode) 98: as.vector(x, mode) 97: as.vector(x, mode) 96: as.vector(x, mode) 95: as.vector(x, mode) 94: as.vector(x, mode) 93: as.vector(x, mode) 92: as.vector(x, mode) 91: as.vector(x, mode) 90: as.vector(x, mode) 89: as.vector(x, mode) 88: as.vector(x, mode) 87: as.vector(x, mode) 86: as.vector(x, mode) 85: as.vector(x, mode) 84: as.vector(x, mode) 83: as.vector(x, mode) 82: as.vector(x, mode) 81: as.vector(x, mode) 80: as.vector(x, mode) 79: as.vector(x, mode) 78: as.vector(x, mode) 77: as.vector(x, mode) 76: as.vector(x, mode) 75: as.vector(x, mode) 74: as.vector(x, mode) 73: as.vector(x, mode) 72: as.vector(x, mode) 71: as.vector(x, mode) 70: as.vector(x, mode) 69: as.vector(x, mode) 68: as.vector(x, mode) 67: as.vector(x, mode) 66: as.vector(x, mode) 65: as.vector(x, mode) 64: as.vector(x, mode) 63: as.vector(x, mode) 62: as.vector(x, mode) 61: as.vector(x, mode) 60: as.vector(x, mode) 59: as.vector(x, mode) 58: as.vector(x, mode) 57: as.vector(x, mode) 56: as.vector(x, mode) 55: as.vector(x, mode) 54: as.vector(x, mode) 53: as.vector(x, mode) 52: as.vector(x, mode) 51: as.vector(x, mode) 50: as.vector(x, mode) 49: as.vector(x, mode) 48: as.vector(x, mode) 47: as.vector(x, mode) 46: as.vector(x, mode) 45: as.vector(x, mode) 44: as.vector(x, mode) 43: as.vector(x, mode) 42: as.vector(x, mode) 41: as.vector(x, mode) 40: as.vector(x, mode) 39: as.vector(x, mode) 38: as.vector(x, mode) 37: as.vector(x, mode) 36: as.vector(x, mode) 35: as.vector(x, mode) 34: as.vector(x, mode) 33: as.vector(x, mode) 32: as.vector(x, mode) 31: as.vector(x, mode) 30: as.vector(x, mode) 29: as.vector(x, mode) 28: as.vector(x, mode) 27: as.vector(x, mode) 26: as.vector(x, mode) 25: as.vector(x, mode) 24: as.vector(x, mode) 23: as.vector(x, mode) 22: as.vector(x, mode) 21: as.vector(x, mode) 20: as.vector(x, mode) 19: as.vector(x, mode) 18: as.vector(x, mode) 17: as.vector(x, mode) 16: as.vector(x, mode) 15: as.vector(x, mode) 14: as.vector(x, mode) 13: as.vector(x, mode) 12: as.vector(x, mode) 11: as.vector(x, mode) 10: as.vector(x, mode) 9: as.vector(x, "character") 8: as.vector(x, "character") 7: as.character.default(statement) 6: as.character(statement) 5: sqliteSendQuery(conn, statement) 4: .local(conn, statement, ...) 3: DBI::dbSendQuery(conn, query) 2: DBI::dbSendQuery(conn, query) 1: (function (sql, outputFile, options) { is_sql_update_query <- function(query) { query <- gsub("^\\s*--.*\n", "", query) if (grepl("^\\s*\\/\\*.*", query)) { query <- gsub(".*\\*\\/", "", query) } grepl("^\\s*(INSERT|UPDATE|DELETE|CREATE).*", query, ignore.case = TRUE) } dir.create(dirname(outputFile), recursive = TRUE, showWarnings = FALSE) max.print <- if (is.null(options$max.print)) getOption("max.print", 1000) else as.numeric(options$max.print) max.print <- if (is.null(options$sql.max.print)) max.print else as.numeric(options$sql.max.print) if (is.null(options$connection)) stop("The 'connection' option (DBI connection) is required for sql chunks.") conn <- get(options$connection, envir = globalenv()) if (is.null(conn)) stop("The 'connection' option must be a valid DBI connection.") varnames_from_sql <- function(conn, sql) { varPos <- DBI::sqlParseVariables(conn, sql) if (length(varPos$start) > 0) { varNames <- substring(sql, varPos$start, varPos$end) sub("^\\?", "", varNames) } } mexists <- function(x, env = globalenv(), inherits = TRUE) { vapply(x, exists, logical(1), where = env, inherits = inherits) } interpolate_from_env <- function(conn, sql, env = globalenv(), inherits = TRUE) { names <- unique(varnames_from_sql(conn, sql)) names_missing <- names[!mexists(names, env, inherits)] if (length(names_missing) > 0) { stop("Object(s) not found: ", paste("\"", names_missing, "\"", collapse = ", ")) } args <- if (length(names) > 0) setNames(mget(names, envir = env, inherits = inherits), names) do.call(DBI::sqlInterpolate, c(list(conn, sql), args)) } varname <- options$output.var query <- interpolate_from_env(conn, sql) if (is.null(varname) && max.print > 0 && !is_sql_update_query(query)) { res <- DBI::dbSendQuery(conn, query) data <- DBI::dbFetch(res, n = max.print) DBI::dbClearResult(res) } else { data <- DBI::dbGetQuery(conn, query) } if (!is.null(varname)) { assign(varname, data, envir = globalenv()) } else { x <- data save(x, file = outputFile) } })("SELECT * FROM EVENTS_ID", "/home/.rstudio-desktop/notebooks/567F01E3-Notebook/1/61A0FD15/csyikkfh4nozt/00006b.rdf", list(connection = "db", engine = "sql", label = "unnamed-chunk-7", max.print = 10)) If I run Cstack_info() after the error I get the following size current direction eval_depth 7969177 15104 1 2
Pandas Multivariate Linear Regression by Group and Saving Results as csv
I am trying to calculate linear regression of Y=C-A column, x = ['Plate X', 'Plate Y', 'Field X'] and group those values by Drum and Plate. Additional question - how to save results as a file, csv preferable. Is pandas package is sufficient for this task or other package needed. Thank you There is my data set: 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}}
From your question it doesnt sound like you want a multivariate regression (i.e. multiple Y's). If you're just predicting a single Y from multiple X's, you can do it like this with pandas, then save the results to a txt file: 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() You mentioned in the question that you want to group the analyses by Drum and Plate. However, every value is the same for the Drum rows. If you want to group by Plate, however, and then run OLS on each subgroup, you can do something like this: 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() If you want to also group by Drum, and note which drum/plate combination each analysis is for, you can do something like this and just add some extra txt to the results file: 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()