dataframe and list all the positive row and negative row - python

I have following set of data:
AC.TO CL=F CNQ.TO CPG.TO ECA.TO IMO.TO SU.TO WJA.TO XEG.TO XFN.TO XGD.TO XOM
Date
2018-03-14 0.016316 0.000493 -0.002574 0.001160 0.012658 -0.008403 -0.003074 0.002465 -0.002755 0.001053 0.001741 -0.012478
2018-03-15 0.002854 0.005089 0.006452 0.010429 -0.019444 -0.003507 0.002135 0.006967 0.004604 0.004208 -0.005213 0.011141
2018-03-16 -0.003557 0.016659 0.019231 0.045872 0.034703 0.009971 0.015621 0.008547 0.023831 0.000000 0.005240 0.009406
2018-03-20 0.043541 0.020270 0.009507 0.035108 0.020935 0.010192 0.024257 -0.001223 0.019178 0.004731 -0.007799 -0.002158
2018-03-21 -0.014483 0.031063 0.032578 0.049234 0.075188 0.024503 0.012306 -0.005714 0.030466 -0.000785 0.013100 0.014191
2018-03-23 -0.011410 0.019383 -0.013548 -0.017279 -0.018277 -0.018224 0.000700 -0.001709 -0.015138 -0.016524 0.027997 -0.008299
2018-03-29 0.032395 0.003711 0.027137 0.024561 0.043446 0.008572 0.014827 0.005516 0.025408 0.009542 0.012987 0.024722
2018-04-03 -0.001140 0.007450 0.043928 -0.002336 0.013991 0.011549 0.010546 0.002114 0.022645 -0.005442 -0.023589 0.024583
2018-04-04 0.002664 0.000787 0.002177 0.012881 -0.012346 0.016101 -0.000227 -0.001688 0.000886 -0.003557 -0.007765 -0.001999
2018-04-09 -0.015498 0.021630 -0.013517 -0.002181 -0.015782 -0.000562 -0.001518 -0.005947 -0.008613 0.005230 -0.010309 0.000000
2018-04-10 -0.001968 0.037763 0.018750 0.036066 0.044461 0.005901 0.006299 -0.016239 0.024327 -0.001095 0.002604 0.029384
2018-04-11 -0.014196 0.017814 0.019585 0.042194 0.027913 0.002793 0.020721 -0.008688 0.017812 -0.008772 0.022511 0.004671
Is there any query to list all the positive rows ( a row contains no negative value)

Here you go!
temp = df[df >= 0]
result = tmp.dropna(axis=0)
Hope this helps!

Related

DtypeWarning with python

The input file looks like this, and the complete file can be found here:
OG0000008 NbL07g11380.1 NbL19g07810.1 NbL19g09170.1 NbL19g19070.1 NbQ01g01670.1 NbQ01g03330.1 NbQ01g04070.1 NbQ01g04670.1 NbQ01g05120.1 NbQ01g05870.1 NbQ01g06940.1 NbQ01g07580.1 NbQ01g08860.1 NbQ01g10050.1 NbQ01g10360.1 NbQ01g14200.1 NbQ01g14790.1 NbQ01g16080.1 NbQ01g17760.1 NbQ01g19270.1 NbQ01g19310.1 NbQ01g19390.1 NbQ01g21260.1 NbQ01g21330.1 NbQ01g21740.1 NbQ01g21910.1 NbQ01g23100.1 NbQ01g24620.1 NbQ01g25340.1 NbQ01g26060.1 NbQ01g26320.1 NbQ02g00750.1 NbQ02g03100.1 NbQ02g03420.1 NbQ02g03610.1 NbQ02g03680.1 NbQ02g05120.1 NbQ02g07460.1 NbQ02g08170.1 NbQ02g08330.1 NbQ02g09220.1 NbQ02g09400.1 NbQ02g10620.1 NbQ02g11310.1 NbQ02g14330.1 NbQ02g14460.1 NbQ02g14520.1 NbQ02g15320.1 NbQ02g17090.1 NbQ02g17130.1 NbQ02g20290.1 NbQ02g23070.1 NbQ02g23420.1 NbQ02g24450.1 NbQ02g24480.1 NbQ02g26700.1 NbQ03g00830.1 NbQ03g01970.1 NbQ03g04460.1 NbQ03g06900.1 NbQ03g09530.1 NbQ03g10620.1 NbQ03g12760.1 NbQ03g13450.1 NbQ03g15540.1 NbQ03g15640.1 NbQ03g17180.1 NbQ03g20740.1 NbQ03g21510.1 NbQ03g24670.1 NbQ04g01350.1 NbQ04g01720.1 NbQ04g08420.1 NbQ04g09090.1 NbQ04g10450.1 NbQ04g11470.1 NbQ04g12120.1 NbQ04g14130.1 NbQ04g15440.1 NbQ04g15860.1 NbQ04g16450.1 NbQ04g16620.1 NbQ04g17760.1 NbQ04g19040.1 NbQ04g20020.1 NbQ05g03320.1 NbQ05g04660.1 NbQ05g05970.1 NbQ05g07500.1 NbQ05g08900.1 NbQ05g09760.1 NbQ05g10830.1 NbQ05g11150.1 NbQ05g11340.1 NbQ05g11510.1 NbQ05g11530.1 NbQ05g11780.1 NbQ05g16980.1 NbQ05g18190.1 NbQ05g21710.1 NbQ05g23400.1 NbQ06g01110.1 NbQ06g01430.1 NbQ06g04200.1 NbQ06g04440.1 NbQ06g05330.1 NbQ06g05770.1 NbQ06g05820.1 NbQ06g06700.1 NbQ06g08620.1 NbQ06g09190.1 NbQ06g10460.1 NbQ06g15220.1 NbQ06g15330.1 NbQ06g15700.1 NbQ06g16320.1 NbQ06g16590.1 NbQ06g17590.1 NbQ06g17670.1 NbQ06g20050.1 NbQ07g01030.1 NbQ07g02010.1 NbQ07g04350.1 NbQ07g04900.1 NbQ07g05610.1 NbQ07g06200.1 NbQ07g07110.1 NbQ07g07690.1 NbQ07g08640.1 NbQ07g10390.1 NbQ07g11920.1 NbQ07g14130.1 NbQ07g15590.1 NbQ07g15620.1 NbQ07g16910.1 NbQ07g17130.1 NbQ07g17950.1 NbQ08g00060.1 NbQ08g02240.1 NbQ08g02300.1 NbQ08g02310.1 NbQ08g03290.1 NbQ08g05330.1 NbQ08g09280.1 NbQ08g14890.1 NbQ08g15820.1 NbQ08g15950.1 NbQ08g19830.1 NbQ08g20150.1 NbQ08g22050.1 NbQ08g22620.1 NbQ09g02100.1 NbQ09g02620.1 NbQ09g03950.1 NbQ09g04200.1 NbQ09g06040.1 NbQ09g06640.1 NbQ09g08160.1 NbQ09g08330.1 NbQ09g09660.1 NbQ09g11220.1 NbQ09g13860.1 NbQ09g15180.1 NbQ09g15310.1 NbQ09g16530.1 NbQ09g17900.1 NbQ09g18100.1 NbQ09g18720.1 NbQ09g19280.1 NbQ09g21840.1 NbQ10g00480.1 NbQ10g01350.1 NbQ10g02870.1 NbQ10g03640.1 NbQ10g03730.1 NbQ10g08070.1 NbQ10g09510.1 NbQ10g11010.1 NbQ10g11760.1 NbQ10g12050.1 NbQ10g12060.1 NbQ10g12910.1 NbQ10g19200.1 NbQ10g19930.1 NbQ10g20390.1 NbQ10g20730.1 NbQ10g21080.1 NbQ10g21140.1 NbQ10g24010.1 NbQ11g00310.1 NbQ11g01210.1 NbQ11g01370.1 NbQ11g04610.1 NbQ11g04800.1 NbQ11g06060.1 NbQ11g07820.1 NbQ11g08390.1 NbQ11g09100.1 NbQ11g09350.1 NbQ11g13660.1 NbQ11g13930.1 NbQ11g16260.1 NbQ11g17360.1 NbQ11g18430.1 NbQ11g21080.1 NbQ11g23280.1 NbQ11g23990.1 NbQ11g25050.1 NbQ12g03770.1 NbQ12g04850.1 NbQ12g07340.1 NbQ12g09080.1 NbQ12g10820.1 NbQ12g12070.1 NbQ12g14750.1 NbQ12g15000.1 NbQ12g15230.1 NbQ12g20380.1 NbQ12g21080.1 NbQ12g21830.1 NbQ12g23960.1 NbQ13g01300.1 NbQ13g02350.1 NbQ13g03860.1 NbQ13g04410.1 NbQ13g08800.1 NbQ13g09850.1 NbQ13g10370.1 NbQ13g11700.1 NbQ13g12420.1 NbQ13g15780.1 NbQ13g16040.1 NbQ13g23160.1 NbQ13g24120.1 NbQ13g24540.1 NbQ13g25080.1 NbQ13g25490.1 NbQ13g28240.1 NbQ13g29770.1 NbQ14g01070.1 NbQ14g03950.1 NbQ14g05360.1 NbQ14g05410.1 NbQ14g06880.1 NbQ14g07270.1 NbQ14g07500.1 NbQ14g10290.1 NbQ14g10770.1 NbQ14g14320.1 NbQ14g17890.1 NbQ14g18710.1 NbQ14g20960.1 NbQ14g22890.1 NbQ15g00150.1 NbQ15g02300.1 NbQ15g02330.1 NbQ15g02350.1 NbQ15g03230.1 NbQ15g06190.1 NbQ15g07120.1 NbQ15g07750.1 NbQ15g09000.1 NbQ15g09050.1 NbQ15g11920.1 NbQ15g12650.1 NbQ15g12840.1 NbQ15g15670.1 NbQ15g15930.1 NbQ15g18670.1 NbQ15g19070.1 NbQ15g20620.1 NbQ15g22880.1 NbQ15g23000.1 NbQ15g26060.1 NbQ16g00880.1 NbQ16g04360.1 NbQ16g06490.1 NbQ16g09100.1 NbQ16g11020.1 NbQ16g11560.1 NbQ16g13810.1 NbQ16g13820.1 NbQ16g17040.1 NbQ16g17130.1 NbQ16g17340.1 NbQ16g18390.1 NbQ16g18430.1 NbQ16g23100.1 NbQ16g23570.1 NbQ16g24270.1 NbQ16g25200.1 NbQ16g25830.1 NbQ16g25880.1 NbQ16g25990.1 NbQ16g26610.1 NbQ16g26660.1 NbQ16g28010.1 NbQ16g28180.1 NbQ17g01150.1 NbQ17g01180.1 NbQ17g01570.1 NbQ17g01950.1 NbQ17g05460.1 NbQ17g05540.1 NbQ17g05980.1 NbQ17g07990.1 NbQ17g08300.1 NbQ17g09330.1 NbQ17g09400.1 NbQ17g10090.1 NbQ17g11220.1 NbQ17g13030.1 NbQ17g15460.1 NbQ17g16690.1 NbQ17g20980.1 NbQ17g22370.1 NbQ17g25040.1 NbQ17g28730.1 NbQ18g02140.1 NbQ18g02740.1 NbQ18g05440.1 NbQ18g06120.1 NbQ18g07470.1 NbQ18g12320.1 NbQ18g12530.1 NbQ18g12850.1 NbQ18g13840.1 NbQ18g14420.1 NbQ18g14930.1 NbQ18g15730.1 NbQ18g17750.1 NbQ18g17850.1 NbQ18g21060.1 NbQ19g01040.1 NbQ19g05480.1 NbQ19g06450.1 NbQ19g06510.1 NbQ19g08330.1 NbQ19g11840.1 NbQ19g11880.1 NbQ19g13750.1 NbQ19g14190.1 NbQ19g14210.1 NbQ19g14920.1 NbQ19g18540.1 NbQ19g19870.1 NbQ19g21020.1 NbQ19g21220.1 NbQ19g22080.1 NbQ19g22800.1 NbQ19g24690.1 NbQ19g24730.1 rna19561
OG0000001 Capann_59V1aChr01g048170.1 NbL01g00020.1 NbL01g00940.1 NbL01g02330.1 NbL01g03550.1 NbL01g03650.1 NbL01g04410.1 NbL01g04920.1 NbL01g06850.1 NbL01g16120.1 NbL01g19150.1 NbL01g20140.1 NbL01g20930.1 NbL01g22230.1 NbL01g24190.1 NbL01g24280.1 NbL01g24300.1 NbL02g00570.1 NbL02g00900.1 NbL02g01270.1 NbL02g02110.1 NbL02g02210.1 NbL02g02470.1 NbL02g03180.1 NbL02g04740.1 NbL02g04750.1 NbL02g06120.1 NbL02g06860.1 NbL02g07280.1 NbL02g07680.1 NbL02g07740.1 NbL02g09780.1 NbL02g11320.1 NbL02g12670.1 NbL02g13080.1 NbL02g14050.1 NbL02g14190.1 NbL02g15010.1 NbL02g15890.1 NbL02g16190.1 NbL02g16730.1 NbL02g17070.1 NbL02g17360.1 NbL02g18820.1 NbL02g19340.1 NbL02g20100.1 NbL02g23950.1 NbL02g24800.1 NbL03g01610.1 NbL03g01680.1 NbL03g01890.1 NbL03g02230.1 NbL03g02600.1 NbL03g03410.1 NbL03g04990.1 NbL03g05400.1 NbL03g08030.1 NbL03g08250.1 NbL03g08690.1 NbL03g10230.1 NbL03g11060.1 NbL03g13030.1 NbL03g14960.1 NbL03g15110.1 NbL03g16690.1 NbL03g16900.1 NbL03g18260.1 NbL03g18950.1 NbL03g21180.1 NbL03g21210.1 NbL03g21530.1 NbL03g22960.1 NbL03g24430.1 NbL04g01140.1 NbL04g01490.1 NbL04g02030.1 NbL04g02560.1 NbL04g03700.1 NbL04g04160.1 NbL04g05240.1 NbL04g05420.1 NbL04g05850.1 NbL04g12420.1 NbL04g12640.1 NbL04g13650.1 NbL04g13780.1 NbL04g14310.1 NbL04g16260.1 NbL04g17750.1 NbL04g18380.1 NbL04g18870.1 NbL04g19030.1 NbL04g19630.1 NbL05g00320.1 NbL05g03060.1 NbL05g03300.1 NbL05g04060.1 NbL05g07620.1 NbL05g08630.1 NbL05g09580.1 NbL05g10060.1 NbL05g11400.1 NbL05g12280.1 NbL05g13170.1 NbL05g16020.1 NbL05g17530.1 NbL05g17730.1 NbL05g18340.1 NbL05g18590.1 NbL05g18600.1 NbL05g19640.1 NbL05g20640.1 NbL05g21000.1 NbL05g21640.1 NbL05g22610.1 NbL06g00640.1 NbL06g00660.1 NbL06g02210.1 NbL06g03150.1 NbL06g03680.1 NbL06g04910.1 NbL06g07950.1 NbL06g09970.1 NbL06g11480.1 NbL06g12220.1 NbL06g12400.1 NbL06g12460.1 NbL06g12850.1 NbL06g13120.1 NbL06g14450.1 NbL06g14780.1 NbL06g16990.1 NbL06g17200.1 NbL06g17760.1 NbL06g20380.1 NbL07g02100.1 NbL07g02540.1 NbL07g02970.1 NbL07g03110.1 NbL07g04840.1 NbL07g05350.1 NbL07g06580.1 NbL07g07530.1 NbL07g08450.1 NbL07g09380.1 NbL07g09870.1 NbL07g10730.1 NbL07g10850.1 NbL07g11080.1 NbL07g12450.1 NbL07g12710.1 NbL07g13110.1 NbL07g13920.1 NbL07g14240.1 NbL07g15520.1 NbL07g16220.1 NbL07g17480.1 NbL08g01820.1 NbL08g02750.1 NbL08g02930.1 NbL08g03510.1 NbL08g03620.1 NbL08g03850.1 NbL08g03970.1 NbL08g04040.1 NbL08g06150.1 NbL08g06410.1 NbL08g06680.1 NbL08g06730.1 NbL08g07620.1 NbL08g08450.1 NbL08g08640.1 NbL08g09910.1 NbL08g10160.1 NbL08g11760.1 NbL08g12570.1 NbL08g13630.1 NbL08g13890.1 NbL08g15050.1 NbL08g15340.1 NbL08g18010.1 NbL08g18420.1 NbL08g19080.1 NbL08g19190.1 NbL09g00900.1 NbL09g02160.1 NbL09g02330.1 NbL09g02470.1 NbL09g04150.1 NbL09g05210.1 NbL09g07010.1 NbL09g09070.1 NbL09g10290.1 NbL09g10500.1 NbL09g11220.1 NbL09g13490.1 NbL09g15290.1 NbL09g15830.1 NbL09g17240.1 NbL09g19250.1 NbL09g19460.1 NbL09g20190.1 NbL09g21040.1 NbL09g21520.1 NbL09g23460.1 NbL10g00080.1 NbL10g03710.1 NbL10g04330.1 NbL10g04560.1 NbL10g05200.1 NbL10g06320.1 NbL10g07510.1 NbL10g07960.1 NbL10g08670.1 NbL10g08970.1 NbL10g11120.1 NbL10g11340.1 NbL10g11820.1 NbL10g13720.1 NbL10g14560.1 NbL10g14770.1 NbL10g16430.1 NbL10g18140.1 NbL10g18380.1 NbL10g19280.1 NbL10g19690.1 NbL10g21210.1 NbL10g22680.1 NbL10g23160.1 NbL10g23560.1 NbL10g24210.1 NbL11g00680.1 NbL11g00970.1 NbL11g01230.1 NbL11g01270.1 NbL11g01520.1 NbL11g01530.1 NbL11g02920.1 NbL11g03540.1 NbL11g03990.1 NbL11g05630.1 NbL11g08950.1 NbL11g08980.1 NbL11g09510.1 NbL11g10840.1 NbL11g11030.1 NbL11g11230.1 NbL11g12430.1 NbL11g13300.1 NbL11g15430.1 NbL11g16390.1 NbL11g16410.1 NbL11g17320.1 NbL11g18090.1 NbL11g21310.1 NbL11g21470.1 NbL11g21780.1 NbL11g21820.1 NbL11g22270.1 NbL11g22310.1 NbL11g23180.1 NbL11g24100.1 NbL12g00130.1 NbL12g01810.1 NbL12g02230.1 NbL12g02720.1 NbL12g02760.1 NbL12g04120.1 NbL12g04550.1 NbL12g06630.1 NbL12g07830.1 NbL12g09170.1 NbL12g10580.1 NbL12g12090.1 NbL12g12490.1 NbL12g12630.1 NbL12g12800.1 NbL12g13320.1 NbL12g13460.1 NbL12g14430.1 NbL12g14970.1 NbL12g15490.1 NbL12g17460.1 NbL12g18190.1 NbL12g18590.1 NbL12g19900.1 NbL12g20690.1 NbL12g22040.1 NbL12g22560.1 NbL13g00350.1 NbL13g01440.1 NbL13g02400.1 NbL13g03210.1 NbL13g03360.1 NbL13g04070.1 NbL13g05250.1 NbL13g08460.1 NbL13g09010.1 NbL13g09140.1 NbL13g10290.1 NbL13g11570.1 NbL13g13370.1 NbL13g14910.1 NbL13g18680.1 NbL13g19510.1 NbL13g23520.1 NbL13g24010.1 NbL13g24190.1 NbL13g24460.1 NbL13g26310.1 NbL13g26640.1 NbL13g26860.1 NbL13g27260.1 NbL13g27960.1 NbL14g02460.1 NbL14g02750.1 NbL14g08750.1 NbL14g08910.1 NbL14g09120.1 NbL14g09540.1 NbL14g09920.1 NbL14g11070.1 NbL14g11150.1 NbL14g12570.1 NbL14g14530.1 NbL14g14860.1 NbL14g15240.1 NbL14g15460.1 NbL14g16620.1 NbL14g16910.1 NbL14g17940.1 NbL14g21150.1 NbL14g21750.1 NbL14g21910.1 NbL15g00790.1 NbL15g01170.1 NbL15g02310.1 NbL15g04220.1 NbL15g05970.1 NbL15g06340.1 NbL15g06440.1 NbL15g07020.1 NbL15g07370.1 NbL15g07470.1 NbL15g09010.1 NbL15g13210.1 NbL15g14550.1 NbL15g14600.1 NbL15g17290.1 NbL15g18170.1 NbL15g19710.1 NbL15g21840.1 NbL15g21930.1 NbL15g23410.1 NbL15g23420.1 NbL15g23430.1 NbL15g25130.1 NbL15g25200.1 NbL16g01760.1 NbL16g02140.1 NbL16g04460.1 NbL16g05010.1 NbL16g05020.1 NbL16g06780.1 NbL16g07540.1 NbL16g07980.1 NbL16g09760.1 NbL16g10610.1 NbL16g12320.1 NbL16g13510.1 NbL16g14420.1 NbL16g15690.1 NbL16g17420.1 NbL16g17790.1 NbL16g17880.1 NbL16g18730.1 NbL16g18940.1 NbL16g19440.1 NbL16g20980.1 NbL16g23180.1 NbL16g23610.1 NbL16g23660.1 NbL16g23910.1 NbL16g24550.1 NbL16g24640.1 NbL16g25300.1 NbL16g25630.1 NbL16g26710.1 NbL17g01590.1 NbL17g02070.1 NbL17g02120.1 NbL17g02920.1 NbL17g03040.1 NbL17g03540.1 NbL17g03700.1 NbL17g03800.1 NbL17g05400.1 NbL17g07510.1 NbL17g08450.1 NbL17g08930.1 NbL17g10090.1 NbL17g14370.1 NbL17g14600.1 NbL17g15390.1 NbL17g15900.1 NbL17g16000.1 NbL17g16910.1 NbL17g17480.1 NbL17g18240.1 NbL17g20020.1 NbL17g20830.1 NbL17g21220.1 NbL17g21690.1 NbL17g25960.1 NbL18g00030.1 NbL18g00150.1 NbL18g00310.1 NbL18g00670.1 NbL18g00700.1 NbL18g01630.1 NbL18g02650.1 NbL18g04460.1 NbL18g05210.1 NbL18g05690.1 NbL18g07270.1 NbL18g07440.1 NbL18g07500.1 NbL18g09090.1 NbL18g09810.1 NbL18g09880.1 NbL18g10500.1 NbL18g10990.1 NbL18g12070.1 NbL18g13060.1 NbL18g17480.1 NbL19g00230.1 NbL19g04470.1 NbL19g04700.1 NbL19g07770.1 NbL19g07870.1 NbL19g09260.1 NbL19g09870.1 NbL19g13480.1 NbL19g14360.1 NbL19g14400.1 NbL19g14720.1 NbL19g17700.1 NbL19g18860.1 NbL19g22750.1 NbQ13g00370.1 NbQ14g10310.1 NbQ17g06050.1
This script appears to have some problems with the file:
import pandas as pd
orthofinder_output = "../OrthoFinder-res/Results_Jan23/Orthogroups/Orthogroups-fixed.txt"
orthogroups = pd.read_csv(orthofinder_output, sep=' ', header=None)
# Extract gene family information
expansions = {}
contractions = {}
for i, row in orthogroups.iterrows():
if len(row) > 2:
expansions[row[0]] = row[2:]
else:
contractions[row[0]] = row[1]
# Print expansions and contractions
print("Expansions:", expansions)
print("Contractions:", contractions)
I got the following error:
geneFamilyExpansionsContractions.py:20: DtypeWarning: Columns (2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,256,257,258,259,260,261,262,263,264,265,266,267,268,269,270,271,272,273,274,275,276,277,278,279,280,281,282,283,284,285,286,287,288,289,290,291,292,293,294,295,296,297,298,299,300,301,302,303,304,305,306,307,308,309,310,311,312,313,314,315,316,317,318,319,320,321,322,323,324,325,326,327,328,329,330,331,332,333,334,335,336,337,338,339,340,341,342,343,344,345,346,347,348,349,350,351,352,353,354,355,356,357,358,359,360,361,362,363,364,365,366,367,368,369,370,371,372,373,374,375,376,377,378,379,380,381,382,383,384,385,386,387,388,389,390,391,392,393,394,395,396,397,398,399,400,401,402,403,404,405,406,407,408,409,410,411,412,413,414,415,416,417,418,419,420,421,422,423,424,425,426,427,428,429,430,431,432,433,434,435,436,437,438,439,440,441,442,443,444,445,446,447,448,449,450,451,452,453,454,455,456,457,458,459,460,461,462,463,464,465,466,467,468,469,470,471,472,473,474,475,476,477,478,479,480,481,482,483,484,485,486,487,488,489,490,491,492,493,494,495,496,497,498,499,500,501,502,503,504,505,506,507,508,509,510,511,512,513,514,515,516,517,518,519,520,521,522,523,524,525,526,527,528,529,530,531,532,533,534,535,536,537,538,539,540,541,542,543,544,545,546,547,548,549,550,551,552,553,554,555,556,557,558,559,560,561,562,563,564,565,566,567,568,569,570,571,572,573,574,575,576,577,578,579,580,581,582,583,584,585,586,587,588,589,590,591,592,593,594,595,596,597,598,599,600,601,602,603,604,605,606,607,608,609,610,611,612,613,614,615,616,617,618,619,620,621,622,623,624,625,626,627,628,629,630,631,632,633,634,635,636,637,638,639,640,641,642,643,644,645,646,647,648,649,650,651,652,653,654,655,656,657,658,659,660,661,662,663,664,665,666,667,668,669,670,671,672,673,674,675,676,677,678,679,680,681,682,683,684,685,686,687,688,689,690,691,692,693,694,695,696,697,698,699,700,701,702,703,704,705,706,707,708,709,710,711,712,713,714,715,716,717,718,719,720,721,722,723,724,725,726,727,728,729,730,731,732,733,734,735,736,737,738,739,740,741,742,743,744,745,746,747,748,749,750,751,752,753,754,755,756,757,758,759,760,761,762,763,764,765,766,767,768,769,770,771,772,773,774,775,776,777,778,779,780,781,782,783,784,785,786,787,788,789,790,791,792,793,794,795,796,797,798,799,800,801,802,803,804,805,806,807,808,809,810,811,812,813,814,815,816,817,818,819,820,821,822,823,824,825,826,827,828,829,830,831,832,833,834,835,836,837,838,839,840,841,842,843,844,845,846,847,848,849,850,851,852,853,854,855,856,857,858,859,860,861,862,863,864,865,866,867,868,869,870,871,872,873,874,875,876,877,878,879,880,881,882,883,884,885,886,887,888,889,890,891,892,893,894,895,896,897,898,899,900,901,902,903,904,905,906,907,908,909,910,911,912,913,914,915,916,917,918,919,920,921,922,923,924,925,926,927,928,929,930,931,932,933,934,935,936,937,938,939,940,941,942,943,944,945,946,947,948,949,950,951,952,953,954,955,956,957,958,959,960,961,962,963,964,965,966,967,968) have mixed types. Specify dtype option on import or set low_memory=False.
orthogroups = pd.read_csv(orthofinder_output, sep=' ', header=None)
...
Expansions:
...
Name: 63241, Length: 967, dtype: object, 'OG0063242': 2 NaN
3 NaN
4 NaN
5 NaN
6 NaN
...
964 NaN
965 NaN
966 NaN
967 NaN
968 NaN
Name: 63242, Length: 967, dtype: object}
Contractions: {}
How can it be fixed?

Python string indice must be an int while converting date (%Y-%m-%d) in a dataframe?

I'm trying to keep this as simple as possible, while keeping the object oriented in-tact. I'm a beginner, but I'm struggling to figure out why I'm getting the error below and how to correct it, while keeping the object oriented style in-tact.
import json
from datetime import datetime, timedelta
from dateutil import tz
import numpy as np
import pandas as pd
import requests
def run(ticker):
today_date, data = scrape_data(ticker)
calculate_gamma_levels(today_date,data)
def scrape_data(ticker):
#Scrape data from CBOE website
raw_data = requests.get(f"https://cdn.cboe.com/api/global/delayed_quotes/options/{ticker}.json")
dict_data = pd.DataFrame.from_dict(raw_data.json())
data = pd.DataFrame(dict_data.loc["options", "data"])
data_update_time = dict_data.timestamp[0]
data["data_update_time"] = data_update_time
data["expiration_date"] = str(20)+ data.option.str.extract(r"[A-Z](\d+)").astype(str)
expiration_date = pd.to_datetime(data["expiration_date"], format="%Y-%m-%d")
print(expiration_date)
today_date = data["data_update_time"][0]
today_date = datetime.strptime(str(today_date), "%Y-%m-%d %H:%M:%S").strftime("%Y-%m-%d")
data["today_date"] = today_date
return data, today_date
def calculate_gamma_levels(today_date,data):
print(today_date)
data['days_till_exp'] = [1/262 if (np.busday_count(today_date.date(), x.date())) == 0 \
else np.busday_count(today_date.date(), x.date())/262 for x in int(data["expiration_date"])]
next_expire = data['expiration_date'].min()
if __name__ == "__main__":
ticker = "SPY"
run(ticker)
The error that I'm getting is the following:
File "c:\python\example option date.py", line 46, in calculate_gamma_levels
else np.busday_count(today_date.date(), x.date())/262 for x in int(data["expiration_date"])]
TypeError: string indices must be integers
I've tried doing the following and several other attempts on the expiration date, but had no success and continued to get the error above.
# expiration_date = datetime.strptime(str(data["expiration_date"].values), "%Y%m%d").strftime("%Y-%m-%d")
# expiration_date = datetime.strptime(str(data["expiration_date"]), "%Y%m%d").strftime("%Y-%m-%d")
print(expiration_date)
# print(data["expiration_date"])
# data["expiration_date"] = pd.to_datetime(data["expiration_date"], format="%Y%m%d")
#print(data["expiration_date"])
Try:
import json
from datetime import datetime, timedelta
from dateutil import tz
import numpy as np
import pandas as pd
import requests
def run(ticker):
data, today_date = scrape_data(ticker)
calculate_gamma_levels(today_date, data)
def scrape_data(ticker):
# Scrape data from CBOE website
raw_data = requests.get(
f"https://cdn.cboe.com/api/global/delayed_quotes/options/{ticker}.json"
)
dict_data = pd.DataFrame.from_dict(raw_data.json())
data = pd.DataFrame(dict_data.loc["options", "data"])
data_update_time = dict_data.timestamp[0]
data["data_update_time"] = data_update_time
data["expiration_date"] = str(20) + data.option.str.extract(
r"[A-Z](\d+)"
).astype(str)
expiration_date = pd.to_datetime(data["expiration_date"], format="%Y-%m-%d")
today_date = data["data_update_time"][0]
today_date = datetime.strptime(
str(today_date), "%Y-%m-%d %H:%M:%S"
).strftime("%Y-%m-%d")
data["today_date"] = today_date
return data, today_date
def calculate_gamma_levels(today_date, data):
data["expiration_date"] = pd.to_datetime(data["expiration_date"])
data["days_till_exp"] = (
np.busday_count(
today_date,
data["expiration_date"].dt.strftime("%Y-%m-%d").to_list(),
)
/ 262
)
data.loc[data["days_till_exp"].eq(0), "days_till_exp"] = 1 / 262
print(data)
next_expire = data["expiration_date"].min()
print(next_expire)
if __name__ == "__main__":
ticker = "SPY"
run(ticker)
Calculates the days_till_exp column divided by 262. Then all zeros are substituted with 1/262. Then minimal value is selected:
option bid bid_size ask ask_size iv open_interest volume delta gamma theta rho vega theo change open high low tick last_trade_price last_trade_time percent_change prev_day_close data_update_time expiration_date today_date days_till_exp
0 SPY220831C00275000 119.94 2.0 121.13 1.0 25.1486 0.0 3.0 1.0000 0.0000 0.0000 0.0000 0.0000 122.4753 0.050 123.43 123.43 123.43 up 123.43 2022-08-31T12:19:26 4.052430e-02 123.380001 2022-08-31 22:55:42 2022-08-31 2022-08-31 0.003817
1 SPY220831P00275000 0.00 0.0 0.01 1711.0 12.0010 1056.0 1.0 0.0000 0.0000 0.0000 0.0000 0.0000 0.0052 0.005 0.01 0.01 0.01 no_change 0.01 2022-08-31T15:10:17 1.000000e+02 0.005000 2022-08-31 22:55:42 2022-08-31 2022-08-31 0.003817
2 SPY220831C00280000 114.94 2.0 116.13 1.0 24.1168 0.0 0.0 1.0000 0.0000 0.0000 0.0000 0.0000 117.4750 0.000 0.00 0.00 0.00 no_change 0.00 None 0.000000e+00 118.385002 2022-08-31 22:55:42 2022-08-31 2022-08-31 0.003817
...
2022-08-31 00:00:00

Save forecast data to csv

Hello I have this code.
forecast = m.predict(future)
forecast[['ds', 'yhat', 'yhat_lower', 'yhat_upper']]
forecast.tail(365)
ds trend yhat_lower yhat_upper trend_lower trend_upper additive_terms additive_terms_lower additive_terms_upper weekly weekly_lower weekly_upper multiplicative_terms multiplicative_terms_lower multiplicative_terms_upper yhat
307 2022-12-30 01:00:00 8744.804921 4151.683644 19973.732090 8744.804921 8744.804921 3425.715807 3425.715807 3425.715807 3425.715807 3425.715807 3425.715807 0.0 0.0 0.0 12170.520728
308 2022-12-30 02:00:00 8743.882714 3948.935733 20003.308794 8743.882714 8743.882714 3691.081394 3691.081394 3691.081394
So I want to download/export this forecast data as csv file.
from google.colab import files
files.download() # ? what I need do here.
Thanks a lot
forecast.to_csv('forecast.csv')
I found the solution.
forecast = m.predict(future)
forecast_data = forecast[['ds', 'yhat', 'yhat_lower', 'yhat_upper']]
#forecast.tail(365)
print (forecast_data)
forecast_data.to_csv('myCsv.csv')
f.close()

Getting StatisticsError when trying to compute mode() for large data set using Statistics library

PROBLEM:
Below is my simple code to compute mean, median and mode for data sets:
import statistics
if __name__ == '__main__':
n=int(input())
a = list(map(int,input().split(' ')))[:n]
a.sort()
print( format( statistics.mean(a),'.1f') )
print( format(statistics.median(a), '.1f') )
print(a)
try:
print( statistics.mode(a) )
except:
print(a[0])
and below is the data set for which mode computes out to be wrong. Point to note here, If the mode for a data set cannot be taken out then I am printing the number with least value, which is why you see a[0] in except.
Data Set
2500
19325 74348 68955 98497 26622 32516 97390 64601 64410 10205 5173 25044 23966 60492 71098 13852 27371 40577 74997 42548 95799 26783 51505 25284 49987 99134 33865 25198 24497 19837 53534 44961 93979 76075 57999 93564 71865 90141 5736 54600 58914 72031 78758 30015 21729 57992 35083 33079 6932 96145 73623 55226 18447 15526 41033 46267 52486 64081 3705 51675 97470 64777 31060 90341 55108 77695 16588 64492 21642 56200 48312 5279 15252 20428 57224 38086 19494 57178 49084 37239 32317 68884 98127 79085 77820 2664 37698 84039 63449 63987 20771 3946 862 1311 77463 19216 57974 73012 78016 9412 90919 40744 24322 68755 59072 57407 4026 15452 82125 91125 99024 49150 90465 62477 30556 39943 44421 68568 31056 66870 63203 43521 78523 58464 38319 30682 77207 86684 44876 81896 58623 24624 14808 73395 92533 4398 8767 72743 1999 6507 49353 81676 71188 78019 88429 68320 59395 95307 95770 32034 57015 26439 2878 40394 33748 41552 64939 49762 71841 40393 38293 48853 81628 52111 49934 74061 98537 83075 83920 42792 96943 3357 83393 73735 32851 12631 954 18806 12518 77451 40057 83048 50251 4042 43390 50802 22087 33164 56529 29586 45201 53718 45822 60832 22942 71260 14629 64736 31441 95195 58122 40597 27533 79588 42012 72119 98585 88519 44490 25289 17586 44822 14592 51428 48069 90282 42412 12944 76050 70793 16815 20712 64466 73404 14806 48857 50014 23121 20402 27509 88681 28108 51497 78993 93631 78013 36779 50217 23025 67506 23403 25015 52071 16229 94964 62133 18117 10038 92156 22253 19201 35213 63072 70702 60003 62184 25174 38807 69217 18269 34780 53985 64378 58515 42341 50198 20372 934 68985 57963 11215 21403 46205 15507 69671 34155 88430 88452 1638 90592 99970 93572 63994 51694 47581 29963 6021 42300 79985 87980 53593 13316 15453 10690 7573 43792 71043 65837 86090 11849 13415 37913 80829 43556 11626 86456 11948 48753 50572 94985 23127 92587 83075 85085 89213 23297 27255 79461 26307 97724 26001 39409 93543 24518 28315 3599 56270 47726 99708 66323 74188 38233 21863 33325 49449 97950 59748 36920 52970 4946 20811 59734 48067 88412 94590 31698 29282 74060 16216 53409 24486 45424 80834 30793 94982 71937 95521 43915 92787 15257 18588 84638 21077 53848 42191 20160 81149 45716 77300 47107 65762 77770 60567 96962 86928 76800 19170 91142 61000 46222 92164 32435 49106 71353 58661 9160 25018 11123 77541 86787 50724 5969 25433 76577 98856 28132 10052 77552 86342 81409 41371 17538 24809 96460 22169 98237 3789 59813 15371 48294 70037 47116 32200 51917 62708 77990 42760 87598 87462 62436 71345 86329 14745 89479 11246 60179 37511 26942 1721 26985 53855 63666 82255 31569 24481 62224 90107 33765 88634 82435 84202 54962 20873 97722 7023 118 2156 28323 35373 24906 24622 44402 22859 91908 17323 31298 83975 56369 74897 5968 98200 42143 76553 93357 30137 21480 92955 18346 68236 67495 8807 10356 51969 80403 10977 60186 61611 74497 45701 96794 52543 43777 78845 39918 84993 85737 53324 53059 8893 31858 36064 64260 73749 64164 52772 15242 70311 43764 79923 21407 86961 34987 34521 34150 38204 51300 77691 92008 96320 61963 84021 2961 34363 28456 71932 61930 54930 42445 96453 65401 13256 79334 64615 9713 60815 28008 69492 23199 59589 28739 72633 94170 10888 51539 76480 33665 81973 81803 24272 7155 70828 65184 69458 9390 65970 98428 765 62446 22955 35044 34202 49648 58515 77039 48268 79160 96421 37434 67204 17068 51985 54255 83409 59296 59036 28023 74513 8622 69405 19712 6680 817 62113 98302 52920 12954 77764 25274 22437 90534 92079 98910 49387 69816 44078 60998 52391 51178 45243 89793 74003 91778 55278 33697 27890 18311 35679 87953 66143 97993 71430 76652 12832 35921 29371 14645 70692 7439 67552 89386 30277 36893 73268 30427 51781 76463 16556 78063 66670 15697 60224 60255 93858 15647 69254 96862 20258 73106 90668 30131 38159 86807 96083 63534 33235 56646 99334 77717 47654 78754 35419 5937 94914 75688 37158 80916 82320 13570 92068 47138 4526 3896 80131 16190 492 40210 32404 62557 23356 73738 64698 16020 87525 48586 47273 13890 72410 52461 56223 72174 41025 30187 6276 10306 32807 48922 60093 18323 11049 63702 22413 13780 84304 83085 46 75596 35294 54872 92212 32064 25302 55609 95164 1524 46990 60773 21909 68402 59472 56689 91087 39631 78193 71526 51792 63272 42985 95265 44552 28294 21810 71384 48003 80544 1363 45802 16952 7529 13362 22473 1221 94395 55384 21619 79257 77566 32224 88127 31954 35651 71426 68599 74190 33407 41231 96316 71415 42254 94181 42133 82767 27639 35673 44389 25222 7332 41911 72559 63687 43008 42840 48593 65086 43754 18516 22700 33797 24547 26764 33146 62195 90700 21335 79793 31396 47616 99154 10299 91775 32512 66035 21502 50806 77264 39799 56009 87600 64349 93885 69236 86648 55846 58090 41524 90695 50647 8308 4564 63060 16932 11331 19852 8639 11040 5202 76658 19618 76458 66905 6581 87747 69766 66507 12010 58124 84856 49117 30234 51748 3611 13964 28011 16438 84796 81080 2963 8912 41050 38175 78210 74440 37042 67605 61848 94040 41364 16395 44176 71400 61297 95912 87090 9691 18671 977 72851 50455 27237 95495 11534 65397 69505 97372 54739 78898 38469 27660 55602 69921 86400 56781 16652 72492 6572 55659 40411 22286 20435 17512 15070 53427 71684 33266 30803 17200 56805 16966 76097 20127 21996 93123 68003 6415 41574 68735 51681 5988 42035 90528 77866 48393 80726 2714 24469 14254 20282 47385 44742 36760 50505 94900 21049 58767 22447 76968 34660 23291 30673 12488 46615 77985 50839 55140 31758 8923 71099 57760 2237 99895 27919 98440 78073 3250 17013 39576 36805 78428 65778 8839 47507 51209 40737 66930 97033 9950 28929 74108 17718 31227 48917 2591 20557 60745 50520 6665 12886 2205 21233 62940 63064 99827 44353 36273 17091 22133 41282 72177 39909 99400 44757 80418 20575 27374 25036 14293 82818 64537 10341 68264 8768 65063 90343 61732 84088 92928 41263 12622 64719 81768 16617 34794 90326 87305 89775 35134 13526 98060 21125 32299 31821 53569 30817 10219 70250 56209 19281 41416 50165 30684 16851 71174 37494 32826 52678 46243 95973 51466 30591 1283 60759 26119 14561 49639 14693 57942 74728 77986 67387 73980 33794 21169 94308 13535 57336 77665 76237 26633 55123 84724 61795 50799 55130 46403 77064 3722 2943 83713 5180 31675 89814 48553 15581 18386 58474 61670 94741 65667 56691 58050 96910 81112 31084 26768 49181 44360 49573 38162 31258 95180 33203 83514 90651 17289 5019 73422 88007 23601 2671 41554 87019 77093 1470 88583 8841 84657 6010 31424 65927 10808 1713 97054 20585 34858 76380 30146 80525 32298 43056 79873 13677 47435 99707 54131 21311 5899 30165 41150 28736 78279 15171 91568 31235 42511 11095 36422 714 45729 68643 55404 77010 37352 14947 34410 87253 2023 99674 21840 63256 50010 78920 37483 13740 86182 36207 12335 86255 69645 1389 85623 34629 35540 97000 67341 37753 10438 88143 49022 21675 7974 25640 52450 37259 51969 57779 28828 89784 39197 84369 74567 70392 27302 82628 46481 78912 53537 20334 29517 20199 37447 43714 82529 68375 23352 16781 91174 3473 38759 22646 10011 29909 12330 43860 27145 38211 4371 96114 84483 23574 89416 70438 67457 34240 96515 87507 15103 50109 18034 37018 94027 82945 85596 22123 27691 11072 36388 30043 55477 36964 29155 44842 89150 4486 69248 48490 98392 50943 4550 77781 66886 81600 41604 53084 40070 88930 60544 73949 33311 30471 66913 15782 78285 76930 72520 37042 68986 43837 94224 46063 85472 72001 92578 84779 72870 66604 3226 23363 25664 59154 81211 14548 82424 10939 47442 51254 56050 95197 77959 23304 8462 89748 98052 94722 55421 90535 26127 16193 15750 76569 6362 12238 67951 34260 38716 26820 48149 98374 36872 27130 17109 65400 94303 26866 34845 88110 94988 96683 63618 23963 9994 20656 54965 53822 94836 28168 6477 93138 73931 29234 87728 67240 52419 64152 41700 721 32516 56375 25567 71196 16585 36696 76479 13480 24419 36434 71672 33742 73445 61854 56844 53164 48181 23848 95085 66647 28945 99487 6971 35820 77999 24366 83595 60755 78496 44267 97352 8016 43857 89120 13576 73019 46834 13282 69406 76455 39531 2963 45758 42325 6010 32380 52541 17340 96073 91868 40931 43220 43681 11625 99374 83824 45877 34162 27499 19445 76280 66428 48016 14662 1681 43725 95891 40204 64845 47840 6416 75532 12342 55280 98806 28520 86284 57025 15664 20195 38125 26821 6954 35942 10786 55679 88640 77839 33797 64511 74958 89019 71955 17252 1004 71078 59048 7702 94236 71137 98008 81859 92890 95632 65782 86928 70030 19485 65253 74982 95361 56903 2476 41790 77964 55352 41374 31762 12290 56482 58584 43220 56178 50987 38724 47817 21042 45094 67390 98430 11533 28884 58759 23162 71657 49440 28925 4693 21136 24328 94257 9808 92577 45852 75930 2151 49505 57759 78168 87797 82824 35706 86404 12993 8938 41606 37152 51915 12097 4388 21510 71798 61425 84956 7638 73699 29255 89177 16400 71453 90108 79062 10561 44604 25540 61945 84835 65707 39679 94848 82746 88580 95163 42939 72722 71129 36800 93351 13066 34621 22886 23586 39954 11246 51623 83339 47847 88135 42996 5184 72033 96604 48362 84720 20388 21389 34906 46035 2665 4920 94465 3196 29137 20767 49061 39634 48028 44199 29097 32274 12110 91829 32788 92025 19474 96282 34088 40272 7778 66750 16996 45025 83489 3589 66008 45773 72467 74043 77751 46004 86743 40481 27323 51069 10215 19206 36450 79667 57211 83658 59228 78735 24408 44752 34321 33803 4365 27439 9012 95864 23583 63450 11932 20021 44815 10170 94900 86241 96663 33082 70515 25822 85348 51426 93063 70527 31342 3883 9497 3495 96230 19127 77857 16310 30724 32368 62646 16378 50298 57695 90448 21023 91959 5547 71630 58750 32224 98322 52304 17361 55421 1200 84993 37888 10372 33355 10461 59193 64165 87728 98676 39184 79931 65773 58268 76007 49713 29842 9767 10021 50290 94426 7856 71069 95504 91908 3412 48516 91025 41357 59057 5349 62818 45034 15298 20004 97875 46490 25490 15783 95208 61362 46869 53645 41987 96858 85583 71207 14943 11977 91706 41540 7046 17197 27004 61897 49647 66239 83245 68753 46041 34322 76758 65595 32143 36923 44198 17143 90388 99829 20676 98555 2975 99141 12876 63617 75137 23903 66499 48565 22359 52964 27846 42921 24974 98425 38987 95924 77927 37264 18518 4709 58272 89422 84397 22040 21772 7116 39569 62032 35663 81633 86315 94020 14401 57097 85565 41264 42272 73643 13524 1556 15936 21353 51970 74909 58214 2817 28486 27908 68226 96761 26786 12991 8599 90118 74512 81723 69567 21050 5233 87266 35718 59743 37364 35688 6443 96488 47811 95945 36255 85715 76180 3852 11822 48624 44174 83234 545 36124 79133 81952 59399 10367 35724 41173 65965 59460 18738 52864 74156 20220 77784 5532 2182 93154 82136 30899 30657 11779 20502 45445 74189 59112 72748 39169 75772 75382 65380 52677 26163 27541 81791 87376 62546 40975 4353 41328 11095 88056 66021 48550 50049 11869 21732 35209 52470 64607 31285 11986 93640 6542 77841 17049 91603 37095 78304 19927 43910 36880 58369 77205 58205 67977 68879 93364 12358 35802 90268 44668 3503 36619 10964 79855 89493 50538 8750 50157 54636 27500 59749 73953 11760 9843 20259 98627 8950 78601 60936 77130 6688 48825 15946 70835 61600 87504 64249 91007 80368 47257 27273 94128 85001 86443 16747 55344 31330 18964 11641 20138 12512 10199 96447 36996 31841 31155 83663 80321 84856 92580 38764 66022 44830 12008 60387 65421 86313 21837 67073 51002 68046 69427 12254 99019 72758 86571 39963 68165 19777 36042 24189 48651 78247 1699 10011 70583 83282 60135 67535 44768 81973 74116 32111 21176 92956 82684 40121 7244 24466 91896 26306 7071 83476 89855 76901 98594 69221 12919 88446 71131 90522 74080 7277 49091 74612 26522 99356 57133 23312 45442 33372 92773 8037 2830 54337 37964 19249 59968 78659 52932 57978 61895 4406 52615 85621 73359 96664 78467 3456 3159 61691 76384 88061 21192 31571 6754 66293 7713 74860 53917 15917 74089 94417 82007 2600 81370 9502 42051 26197 54 75490 23717 73795 36581 53145 81594 59355 9899 66733 70159 85392 47845 85594 31047 2769 7809 81154 83826 79134 25761 97453 91087 31423 41468 42292 37745 43911 83645 20238 94043 8861 68668 20365 18282 36438 63231 31537 11506 83709 48569 58537 34074 141 55431 33652 43414 97246 483 59823 8422 4516 30307 26607 51951 94670 278 95417 48230 87851 81702 43732 63408 50884 82397 37076 38158 80890 5734 21712 28188 65118 48846 7900 7044 49899 31956 97047 70075 82348 89353 55822 68370 99590 72052 23036 83541 5565 9112 10135 22703 24274 68868 41813 93640 98765 30763 95298 71151 66416 23785 92895 64952 33325 62359 81647 84230 14163 2797 24321 15500 5378 44396 52547 27959 6027 12498 54060 85501 52590 55861 86023 26810 25248 81167 2184 34288 29902 7188 26365 259 12140 12384 44792 97795 49326 80617 96793 18843 87679 47442 51844 55797 61131 33945 97008 92433 73116 8928 96289 39569 52938 54555 83529 17004 70692 10103 56356 18768 48515 67098 90396 8204 93156 15376 11196 68935 18759 33949 84573 15934 93430 31352 71658 50124 74916 43918 92866 93975 66779 67560 6575 84036 23523 12070 99556 73084 4312 14498 4161 32455 89492 27427 65249 26614 34000 89005 54775 15282 18750 26159 11056 5553 40818 79956 86607 40675 50002 34664 39354 41957 67729 38601 36228 37831 25987 96623 66850 31847 85868 79806 55247 82795 90196 12632 7644 14648 79119 78278 27701 55037 27372 54045 28914 99063 66882 96018 77927 43135 11894 95424 68016 72522 99412 56436 93986 50271 89743 94768 36988 63401 35692 16157 17475 9370 11231 44413 97692 13103 57060 92127 79290 41626 56994 2637 8497 67335 46138 30900 62623 36329 59168 38478 55376 11015 1305 73712 77036 72827 88068 96784 5662 63256 61103 78741 47518 85964 53335 40062 63396 82139 94070 72478 93895 79380 12673 66730 21929 26310 74983 30147 50684 273 94126 97034 9491 36082 49630 37437 7718 88957 48078 76736 88348 17976 54328 4970 43163 45742 35204 35351 91551 6124 67178 24716 17285 60265 24938 23780 60055 50738 83812 2403 42841 40128 85074 88427 33527 44385 41547 50313 53409 85647 8128 74427 75864 42837 80339 43755 96377 40343 20319 84881 22778 14127 14218 64683 80165 47769 79428 63211 55466 44006 72059 78664 4665 10359 59943 16756 44644 20458 70070 46509 59710 88534 87105 13153 80444 66747 69879 53832 14466 6798 43829 46245 58710 19380 24639 66733 39264 43283 41566 35106 30387 2879 82930 38511 72038 84050 73115 75029 63880 85012 36944 7846 18360 60276 44372 23370 46900 35190 95352 28545 60567 8432 97358 56250 81698 85125 10335 72282 97523 90472 51939 21597 83385 25271 68248 8791 82485 89164 95215 56550 46657 36404 35773 15051 72789 5083 59111 80195 38090 78967 91950 77402 43674 11220 75062 59935 66881 82180 2184 220 44778 53053 1920 6708 93213 78174 50604 69152 37538 34174 75321 52740 28455 23803 96360 68638 37458 49366 88209 93339 3273 15711 63138 52419 93169 89108 12599 62628 64408 44625 6514 55202 5857 1716 88630 82526 65319 5585 52404 3552 96473 79771 15107 77399 38599 72213 52512 53927 74044 16938 18707 40121 45472 81515 12100 58725 99857 47152 13177 45151 61848 92998 16782 6203 13255 14617 83157 7392 79743 32779 72374 30295 89061 77386 99001 509 72929 25787 60786 25810 73685 65288 27023 81071 51613 32344 10971 42312 16378 25821 48428 83799 91649 11161
Output
49921.5
49253.5
46 (Wrong)
So just to save you the trouble, I am printing the list and if you look closely, 2184 appears twice which should be the mode, but 46 is printed instead.
I would like to know the reason behind this peculiar behavior of mode() function.
From the documentation (emphasis mine):
If data is empty, or if there is not exactly one most common value, StatisticsError is raised.
In your dataset, the following numbers appear exactly twice and so the mode isn't well-defined:
2184
2963
6010
10011
11095
11246
16378
32224
32516
33325
33797
37042
39569
40121
43220
47442
51969
52419
53409
55421
58515
60567
61848
63256
66733
70692
77927
81973
83075
84856
84993
86928
87728
91087
91908
93640
Just to add a working solution to what #NPE said.
I was able to compute correct mode for the data said by importing scipy
import statistics
from scipy import stats
if __name__ == '__main__':
n=int(input())
a = list(map(int,input().split(' ')))[:n]
a.sort()
print( format( statistics.mean(a),'.1f') )
print( format(statistics.median(a), '.1f') )
print(a)
try:
print( statistics.mode(a) )
except:
print(a[0])
print(int(stats.mode(a)[0])) # This will print the correct mode

How to enumerate all vaild timezone for Linux?

I'm working on a pre-configuration cloud-init script for Linux OS and need to list all vaild timezone for user to choose
Currently my approach is
cd /usr/share/zoneinfo/
find
However, this is giving some duplicated names in posix and right. And I'm not sure if all the correct names are included.
Is there anyway (python module or program) to enumerate all vaild linux timezone names?
Thanks
You can use the pytz library.
>>> import pytz
>>> for time_zone in pytz.all_timezones:
>>> print( time_zone )
Africa/Abidjan
Africa/Accra
Africa/Addis_Ababa
Africa/Algiers
Africa/Asmara
Africa/Asmera
Africa/Bamako
Africa/Bangui
Africa/Banjul
Africa/Bissau
Africa/Blantyre
Africa/Brazzaville
Africa/Bujumbura
Africa/Cairo
Africa/Casablanca
Africa/Ceuta
Africa/Conakry
Africa/Dakar
Africa/Dar_es_Salaam
Africa/Djibouti
Africa/Douala
Africa/El_Aaiun
Africa/Freetown
Africa/Gaborone
Africa/Harare
Africa/Johannesburg
Africa/Juba
Africa/Kampala
Africa/Khartoum
Africa/Kigali
Africa/Kinshasa
Africa/Lagos
Africa/Libreville
Africa/Lome
Africa/Luanda
Africa/Lubumbashi
Africa/Lusaka
Africa/Malabo
Africa/Maputo
Africa/Maseru
Africa/Mbabane
Africa/Mogadishu
Africa/Monrovia
Africa/Nairobi
Africa/Ndjamena
Africa/Niamey
Africa/Nouakchott
Africa/Ouagadougou
Africa/Porto-Novo
Africa/Sao_Tome
Africa/Timbuktu
Africa/Tripoli
Africa/Tunis
Africa/Windhoek
America/Adak
America/Anchorage
America/Anguilla
America/Antigua
America/Araguaina
America/Argentina/Buenos_Aires
America/Argentina/Catamarca
America/Argentina/ComodRivadavia
America/Argentina/Cordoba
America/Argentina/Jujuy
America/Argentina/La_Rioja
America/Argentina/Mendoza
America/Argentina/Rio_Gallegos
America/Argentina/Salta
America/Argentina/San_Juan
America/Argentina/San_Luis
America/Argentina/Tucuman
America/Argentina/Ushuaia
America/Aruba
America/Asuncion
America/Atikokan
America/Atka
America/Bahia
America/Bahia_Banderas
America/Barbados
America/Belem
America/Belize
America/Blanc-Sablon
America/Boa_Vista
America/Bogota
America/Boise
America/Buenos_Aires
America/Cambridge_Bay
America/Campo_Grande
America/Cancun
America/Caracas
America/Catamarca
America/Cayenne
America/Cayman
America/Chicago
America/Chihuahua
America/Coral_Harbour
America/Cordoba
America/Costa_Rica
America/Creston
America/Cuiaba
America/Curacao
America/Danmarkshavn
America/Dawson
America/Dawson_Creek
America/Denver
America/Detroit
America/Dominica
America/Edmonton
America/Eirunepe
America/El_Salvador
America/Ensenada
America/Fort_Wayne
America/Fortaleza
America/Glace_Bay
America/Godthab
America/Goose_Bay
America/Grand_Turk
America/Grenada
America/Guadeloupe
America/Guatemala
America/Guayaquil
America/Guyana
America/Halifax
America/Havana
America/Hermosillo
America/Indiana/Indianapolis
America/Indiana/Knox
America/Indiana/Marengo
America/Indiana/Petersburg
America/Indiana/Tell_City
America/Indiana/Vevay
America/Indiana/Vincennes
America/Indiana/Winamac
America/Indianapolis
America/Inuvik
America/Iqaluit
America/Jamaica
America/Jujuy
America/Juneau
America/Kentucky/Louisville
America/Kentucky/Monticello
America/Knox_IN
America/Kralendijk
America/La_Paz
America/Lima
America/Los_Angeles
America/Louisville
America/Lower_Princes
America/Maceio
America/Managua
America/Manaus
America/Marigot
America/Martinique
America/Matamoros
America/Mazatlan
America/Mendoza
America/Menominee
America/Merida
America/Metlakatla
America/Mexico_City
America/Miquelon
America/Moncton
America/Monterrey
America/Montevideo
America/Montreal
America/Montserrat
America/Nassau
America/New_York
America/Nipigon
America/Nome
America/Noronha
America/North_Dakota/Beulah
America/North_Dakota/Center
America/North_Dakota/New_Salem
America/Ojinaga
America/Panama
America/Pangnirtung
America/Paramaribo
America/Phoenix
America/Port-au-Prince
America/Port_of_Spain
America/Porto_Acre
America/Porto_Velho
America/Puerto_Rico
America/Rainy_River
America/Rankin_Inlet
America/Recife
America/Regina
America/Resolute
America/Rio_Branco
America/Rosario
America/Santa_Isabel
America/Santarem
America/Santiago
America/Santo_Domingo
America/Sao_Paulo
America/Scoresbysund
America/Shiprock
America/Sitka
America/St_Barthelemy
America/St_Johns
America/St_Kitts
America/St_Lucia
America/St_Thomas
America/St_Vincent
America/Swift_Current
America/Tegucigalpa
America/Thule
America/Thunder_Bay
America/Tijuana
America/Toronto
America/Tortola
America/Vancouver
America/Virgin
America/Whitehorse
America/Winnipeg
America/Yakutat
America/Yellowknife
Antarctica/Casey
Antarctica/Davis
Antarctica/DumontDUrville
Antarctica/Macquarie
Antarctica/Mawson
Antarctica/McMurdo
Antarctica/Palmer
Antarctica/Rothera
Antarctica/South_Pole
Antarctica/Syowa
Antarctica/Vostok
Arctic/Longyearbyen
Asia/Aden
Asia/Almaty
Asia/Amman
Asia/Anadyr
Asia/Aqtau
Asia/Aqtobe
Asia/Ashgabat
Asia/Ashkhabad
Asia/Baghdad
Asia/Bahrain
Asia/Baku
Asia/Bangkok
Asia/Beirut
Asia/Bishkek
Asia/Brunei
Asia/Calcutta
Asia/Choibalsan
Asia/Chongqing
Asia/Chungking
Asia/Colombo
Asia/Dacca
Asia/Damascus
Asia/Dhaka
Asia/Dili
Asia/Dubai
Asia/Dushanbe
Asia/Gaza
Asia/Harbin
Asia/Hebron
Asia/Ho_Chi_Minh
Asia/Hong_Kong
Asia/Hovd
Asia/Irkutsk
Asia/Istanbul
Asia/Jakarta
Asia/Jayapura
Asia/Jerusalem
Asia/Kabul
Asia/Kamchatka
Asia/Karachi
Asia/Kashgar
Asia/Kathmandu
Asia/Katmandu
Asia/Kolkata
Asia/Krasnoyarsk
Asia/Kuala_Lumpur
Asia/Kuching
Asia/Kuwait
Asia/Macao
Asia/Macau
Asia/Magadan
Asia/Makassar
Asia/Manila
Asia/Muscat
Asia/Nicosia
Asia/Novokuznetsk
Asia/Novosibirsk
Asia/Omsk
Asia/Oral
Asia/Phnom_Penh
Asia/Pontianak
Asia/Pyongyang
Asia/Qatar
Asia/Qyzylorda
Asia/Rangoon
Asia/Riyadh
Asia/Saigon
Asia/Sakhalin
Asia/Samarkand
Asia/Seoul
Asia/Shanghai
Asia/Singapore
Asia/Taipei
Asia/Tashkent
Asia/Tbilisi
Asia/Tehran
Asia/Tel_Aviv
Asia/Thimbu
Asia/Thimphu
Asia/Tokyo
Asia/Ujung_Pandang
Asia/Ulaanbaatar
Asia/Ulan_Bator
Asia/Urumqi
Asia/Vientiane
Asia/Vladivostok
Asia/Yakutsk
Asia/Yekaterinburg
Asia/Yerevan
Atlantic/Azores
Atlantic/Bermuda
Atlantic/Canary
Atlantic/Cape_Verde
Atlantic/Faeroe
Atlantic/Faroe
Atlantic/Jan_Mayen
Atlantic/Madeira
Atlantic/Reykjavik
Atlantic/South_Georgia
Atlantic/St_Helena
Atlantic/Stanley
Australia/ACT
Australia/Adelaide
Australia/Brisbane
Australia/Broken_Hill
Australia/Canberra
Australia/Currie
Australia/Darwin
Australia/Eucla
Australia/Hobart
Australia/LHI
Australia/Lindeman
Australia/Lord_Howe
Australia/Melbourne
Australia/NSW
Australia/North
Australia/Perth
Australia/Queensland
Australia/South
Australia/Sydney
Australia/Tasmania
Australia/Victoria
Australia/West
Australia/Yancowinna
Brazil/Acre
Brazil/DeNoronha
Brazil/East
Brazil/West
CET
CST6CDT
Canada/Atlantic
Canada/Central
Canada/East-Saskatchewan
Canada/Eastern
Canada/Mountain
Canada/Newfoundland
Canada/Pacific
Canada/Saskatchewan
Canada/Yukon
Chile/Continental
Chile/EasterIsland
Cuba
EET
EST
EST5EDT
Egypt
Eire
Etc/GMT
Etc/GMT+0
Etc/GMT+1
Etc/GMT+10
Etc/GMT+11
Etc/GMT+12
Etc/GMT+2
Etc/GMT+3
Etc/GMT+4
Etc/GMT+5
Etc/GMT+6
Etc/GMT+7
Etc/GMT+8
Etc/GMT+9
Etc/GMT-0
Etc/GMT-1
Etc/GMT-10
Etc/GMT-11
Etc/GMT-12
Etc/GMT-13
Etc/GMT-14
Etc/GMT-2
Etc/GMT-3
Etc/GMT-4
Etc/GMT-5
Etc/GMT-6
Etc/GMT-7
Etc/GMT-8
Etc/GMT-9
Etc/GMT0
Etc/Greenwich
Etc/UCT
Etc/UTC
Etc/Universal
Etc/Zulu
Europe/Amsterdam
Europe/Andorra
Europe/Athens
Europe/Belfast
Europe/Belgrade
Europe/Berlin
Europe/Bratislava
Europe/Brussels
Europe/Bucharest
Europe/Budapest
Europe/Chisinau
Europe/Copenhagen
Europe/Dublin
Europe/Gibraltar
Europe/Guernsey
Europe/Helsinki
Europe/Isle_of_Man
Europe/Istanbul
Europe/Jersey
Europe/Kaliningrad
Europe/Kiev
Europe/Lisbon
Europe/Ljubljana
Europe/London
Europe/Luxembourg
Europe/Madrid
Europe/Malta
Europe/Mariehamn
Europe/Minsk
Europe/Monaco
Europe/Moscow
Europe/Nicosia
Europe/Oslo
Europe/Paris
Europe/Podgorica
Europe/Prague
Europe/Riga
Europe/Rome
Europe/Samara
Europe/San_Marino
Europe/Sarajevo
Europe/Simferopol
Europe/Skopje
Europe/Sofia
Europe/Stockholm
Europe/Tallinn
Europe/Tirane
Europe/Tiraspol
Europe/Uzhgorod
Europe/Vaduz
Europe/Vatican
Europe/Vienna
Europe/Vilnius
Europe/Volgograd
Europe/Warsaw
Europe/Zagreb
Europe/Zaporozhye
Europe/Zurich
GB
GB-Eire
GMT
GMT+0
GMT-0
GMT0
Greenwich
HST
Hongkong
Iceland
Indian/Antananarivo
Indian/Chagos
Indian/Christmas
Indian/Cocos
Indian/Comoro
Indian/Kerguelen
Indian/Mahe
Indian/Maldives
Indian/Mauritius
Indian/Mayotte
Indian/Reunion
Iran
Israel
Jamaica
Japan
Kwajalein
Libya
MET
MST
MST7MDT
Mexico/BajaNorte
Mexico/BajaSur
Mexico/General
NZ
NZ-CHAT
Navajo
PRC
PST8PDT
Pacific/Apia
Pacific/Auckland
Pacific/Chatham
Pacific/Chuuk
Pacific/Easter
Pacific/Efate
Pacific/Enderbury
Pacific/Fakaofo
Pacific/Fiji
Pacific/Funafuti
Pacific/Galapagos
Pacific/Gambier
Pacific/Guadalcanal
Pacific/Guam
Pacific/Honolulu
Pacific/Johnston
Pacific/Kiritimati
Pacific/Kosrae
Pacific/Kwajalein
Pacific/Majuro
Pacific/Marquesas
Pacific/Midway
Pacific/Nauru
Pacific/Niue
Pacific/Norfolk
Pacific/Noumea
Pacific/Pago_Pago
Pacific/Palau
Pacific/Pitcairn
Pacific/Pohnpei
Pacific/Ponape
Pacific/Port_Moresby
Pacific/Rarotonga
Pacific/Saipan
Pacific/Samoa
Pacific/Tahiti
Pacific/Tarawa
Pacific/Tongatapu
Pacific/Truk
Pacific/Wake
Pacific/Wallis
Pacific/Yap
Poland
Portugal
ROC
ROK
Singapore
Turkey
UCT
US/Alaska
US/Aleutian
US/Arizona
US/Central
US/East-Indiana
US/Eastern
US/Hawaii
US/Indiana-Starke
US/Michigan
US/Mountain
US/Pacific
US/Pacific-New
US/Samoa
UTC
Universal
W-SU
WET
Zulu

Categories

Resources