read_csv跳过了2个特定值,为什么会发生这种情况?

时间:2018-08-15 20:37:20

标签: python excel pandas csv

我想使用我创建并测试的函数来读取更改国家/地区的价值的方法,现在...我现在意识到GDP不能拯救伊朗,伊斯兰共和国和中国香港特别行政区。我测试了其他国家,它们都被保存了。要填充我正在使用的数据框

GDP = pd.read_csv('world_bank.csv', skiprows=4) # Works

csv文件看起来像这样,尽管我首先要做的是围绕这2个值的“”,但是文档中有几个这样的值,它们可以正常读取...

  Data Source,World Development Indicators,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
Last Updated Date,2016-07-22,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
Country Name,Country Code,Indicator Name,Indicator Code,1960,1961,1962,1963,1964,1965,1966,1967,1968,1969,1970,1971,1972,1973,1974,1975,1976,1977,1978,1979,1980,1981,1982,1983,1984,1985,1986,1987,1988,1989,1990,1991,1992,1993,1994,1995,1996,1997,1998,1999,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015
Aruba,ABW,GDP at market prices (constant 2010 US$),NY.GDP.MKTP.KD,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,2467703910.61453,,,,,
Andorra,AND,GDP at market prices (constant 2010 US$),NY.GDP.MKTP.KD,,,,,,,,,,,1022871401.93761,1070429536.96666,1157666822.22471,1247831302.28061,1317944270.10389,1325090206.69843,1368868423.74087,1407724771.11631,1428319832.5687,1428913249.71927,1460474058.82573,1458539387.76721,1476719523.0981,1502859168.80367,1529680509.57141,1565191061.36678,1616111761.51642,1705759462.17548,1792656379.78858,1879188446.01576,1950247955.3502,1999901280.7926,2018484671.13457,1997664169.00582,2045272407.14157,2101670670.58746,2199392933.59256,2398826713.99845,2475464141.15257,2576935425.08679,2606977004.92985,2765136580.02845,2942847625.89494,3296693262.49151,3562720066.76084,3842026792.01624,4018195653.51015,4021331428.40105,3675727910.50681,3535389132.60241,3346317328.52461,3185604581.52029,3129537611.8862,3127549907.58377,,
IDA blend,IDB,GDP at market prices (constant 2010 US$),NY.GDP.MKTP.KD,114843734496.467,116825126778.394,121643012470.776,130734109731.368,137328520363.959,145014531146.25,144058056666.588,132890664623.984,134210156587.344,155382231058.333,183359838772.403,201110581022.513,207617530331.052,219438392800.854,238570050445.152,234626261690.864,250046897890.65,262680672413.176,260220670867.475,275041817716.204,289461610552.389,276500129859.62,282827934807.378,282421335436.72,285963227093.922,304186491207.154,299719850430.217,292729058944.008,309344459545.3,324457648875.288,345746839000.192,350924822772.177,356038812480.683,364514117515.583,373115707944.433,383892894576.167,404244192516.042,417563815701.912,431248084865.196,441355516730.99,461954366198.435,477233675738.881,494161983121.63,525287801517.408,609832448958.441,641846930294.024,686229409346.005,728044694230.304,763260853189.323,802728376068.952,851672684956.445,896205368021.057,940445925880,989736427045.418,1048143618028.7,1093273220752.24
Indonesia,IDN,GDP at market prices (constant 2010 US$),NY.GDP.MKTP.KD,50690456241.3595,53785065695.4124,54812177702.1083,53577239297.2871,55426439386.0439,55951372227.5444,57546225952.997,58193619222.8912,65196743209.4572,70071755312.3025,75784072052.4458,81086959458.005,87478799388.7145,96030870176.5996,103960020075.396,110388314055.746,116998527975.214,127103065077.058,138803610829.959,148648426511.93,161618000132.291,174786943468.06,176716720143.147,191649119920.851,205394486074.898,212537159009.816,225213972675.202,237150320298.847,252222832803.733,275136556654.608,299903175261.402,326677919382.138,350265703789.668,375674242085.325,404000330435.902,437921644681.252,471391060076.756,493545839076.339,428759439289.54,432151483136.748,453413615265.361,469933588204.66,491078134359.3,514553481857.514,540440018909.465,571204952340.344,602626661363.277,640863456970.63,679403085754.142,710851779404.06,755094157594.527,801681837683.133,850023658571.777,897261714696.733,942339147749.082,987514144907.28
IDA only,IDX,GDP at market prices (constant 2010 US$),NY.GDP.MKTP.KD,,,,,,,176116462408.66,179363247751.575,188465161056.638,196241783973.108,204753945215.485,210897909288.906,209665034578.705,215624504931.857,228947150724.273,229293873279.911,239948485849.848,248938643905.808,255117906941.547,257174213511.972,257306403710.239,266608586082.111,268645682060.858,270646895654.07,274648297782.878,279940445459.309,290802664775.217,302403576284.622,311755987785.511,319476139005.429,322214490537.895,326846953322.727,327215111462.726,332228448793.252,336305472889.315,351950766643.983,369675389456.755,385486862425.308,400347027194.538,414961653780.11,429165238432.989,449406495034.163,464629472677.006,486849165353.847,513154960735.692,545656117338.463,580412514329.853,620804001159.904,656668710237.39,685883500935.601,725816940326.799,756250338457.05,790635811693.669,836519782382.788,883206506653.875,927949517271.335
Isle of Man,IMN,GDP at market prices (constant 2010 US$),NY.GDP.MKTP.KD,,,,,,,,,,,,,,,,,,,,,,,,,974215651.253195,978296865.282151,1165205747.92153,1280518548.80592,1431995653.36528,1530018808.32589,1594080341.10434,1619665137.49349,1632416698.02423,1674341664.65313,1741376689.82916,1815923292.79581,1956039869.74861,2123897982.21156,2410820855.92323,2740939768.55048,2887261118.05137,3042485078.26709,3221047763.36132,3424868543.53407,3602961595.49426,3815536439.37964,4109332802.38461,4415768422.34478,4850662591.66821,4953843516.88238,5420291954.71889,5681266119.97835,6036319157.98014,6307561781.47327,,
India,IND,GDP at market prices (constant 2010 US$),NY.GDP.MKTP.KD,142574928610,147882626117.08,152217254789.058,161341694767.343,173366410805.097,168796870765.197,168703477532.633,181906149319.231,188069000822.198,200368149829.309,210701595633.017,214163276165.591,212978307947.393,219997053101.027,222604757943.431,242972897434.093,247013788528.845,264934057379.626,280068500423.3,265398000678.424,283274736343.697,300288793820.099,310726031244.58,333374518880.449,346111885322.433,364297639428.366,381698549946.995,396834254902.771,435040595513.124,460913953347.585,486418417531.595,491559040260.466,518508253530.734,543141420335.337,579308795091.949,623188492510.657,670236246400.872,697379613646.005,740508468803.062,806012037863.705,836970888960.893,877346082285.568,910720110737.538,982306185613.413,1060133682046.38,1158565308177.29,1265894322131.09,1374865195244.5,1428360609657.8,1549482541544.7,1708458876829.92,1821872415623.62,1924235460945.25,2051981849791.69,2200616575310.97,2367206118959.06
Not classified,INX,GDP at market prices (constant 2010 US$),NY.GDP.MKTP.KD,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
Ireland,IRL,GDP at market prices (constant 2010 US$),NY.GDP.MKTP.KD,,,,,,,,,,,35646476821.192,36883369668.8742,39277029668.8742,41131466490.0662,42883761192.053,45309543576.1589,45941524768.2119,49713921324.5033,53286725960.2649,54924246357.6159,56615544635.7616,58498133774.8345,59833920132.4503,59687745165.5629,62286771920.5298,64208701854.3046,63933676423.8411,66914961986.755,70406192715.2318,74499552185.4305,80807077615.8941,82366362913.9073,85120096291.3907,87412047814.5696,92443334039.7351,101349715231.788,110743827284.768,123122771920.53,134096925960.265,148528494701.987,163721106887.417,173271782251.656,183558373774.834,190611046622.517,199007714966.887,211613113509.934,224965327549.669,237434595099.338,232300285298.013,219202343576.159,220076114437.086,225771869801.325,226113050728.477,229356195761.589,241281270463.576,260128705960.265
"Iran, Islamic Rep.",IRN,GDP at market prices (constant 2010 US$),NY.GDP.MKTP.KD,55008199861.362,60724056997.4978,65526885363.1927,70141337925.7686,76085976411.7395,89047763860.6423,99290400337.9273,110463353581.338,126374696820.65,145983827472.444,161936358582.348,184124203150.852,210820400546.88,226508983528.938,239648884838.343,238867111255.166,282485286342.747,274650337458.608,239382881270.266,210607239021.737,165116813883.768,155710460310.332,191790513393.427,213053784552.521,197842062853.222,201537060006.584,181816848980.232,181503928205.772,170464865427.365,180917968164.33,205513632859.481,231647051483.288,239286729358.449,235766794094.242,231762799356.709,237327527424.692,252399073803.436,255807469064.417,261128294555.753,266357901072.916,281927925364.048,288672128262.342,311993456682.879,338947502385.457,353646523406.399,368530410531.603,389552313541.27,425064554419.087,428990857822.095,438920754763.986,467790215915.476,485330901134.448,453256899727.832,444592553889.771,463902735245.89,
Iraq,IRQ,GDP at market prices (constant 2010 US$),NY.GDP.MKTP.KD,,,,,,,,,13470458663.4932,13907465459.571,14539470348.6708,15320901820.5358,15893184046.4595,16595465000.9602,19269553239.2887,21676448518.7612,25399401037.7733,25881979343.8993,30296659415.1873,36619346656.0894,45683999700.3624,45351087827.0686,46908434219.6712,40775948070.5521,40170326687.3795,40754361565.8638,42648457432.5216,46617016405.5969,46608141953.6336,45154650633.8524,71262089027.4253,25620782636.5138,33971162223.5539,44260969337.2328,45967022762.6076,46941533526.9572,52114859315.0861,63182979850.0698,85206731245.2155,100188005390.994,101597124451.063,103939260216.262,96767263938.4528,64736488641.8064,99796330254.8975,104187984720.99,114771608149.415,116352699697.206,125926324446.493,130181751588.159,138516722649.573,148969847232.097,169730925971.545,180885914501.784,177054265948.267,180772405533.181
Iceland,ISL,GDP at market prices (constant 2010 US$),NY.GDP.MKTP.KD,2054312977.86783,2052573756.51784,2223218842.49829,2451840948.15596,2694978834.94366,2893645379.31315,3146432314.68332,3106558777.92247,2936477594.24631,3006206839.62042,3230366457.3002,3652279375.79453,3877892887.70289,4141822653.95306,4378167154.7703,4406456904.26679,4669053865.37175,5080970742.4138,5386678250.8111,5648502185.01364,5973173611.64511,6227929890.59389,6362114765.16216,6225255388.90952,6482303544.28681,6695755518.16154,7115615677.28878,7723711906.23829,7716781726.05443,7736724965.60096,7827195932.16068,7809700152.48467,7546209136.31835,7645324780.06705,7921233689.2945,7930468557.40017,8309946429.12654,8718229854.27244,9286660346.13365,9673283176.45846,10130213932.5501,10511376754.9234,10559030951.7694,10848541108.6879,11740326733.5723,12440092240.952,12963368582.5961,14193969535.7889,14403867348.1575,13729597602.4568,13236887873.0516,13500053195.3882,13659749592.2017,14191929403.0356,14451167765.0362,15023018132.9136
Israel,ISR,GDP at market prices (constant 2010 US$),NY.GDP.MKTP.KD,16531949036.5479,18384169709.2935,20251287530.0531,22417307095.7701,24196611804.6694,26397043366.4127,26376019480.2727,27165986591.4542,31578274414.3908,35862089476.7697,38482650593.7524,42802052510.4047,48649171993.32,50275291533.3877,53714251341.8311,55496674635.0286,56226929805.8059,56222450137.2094,58933223587.7054,62637058033.6486,66941033623.9661,70387063175.6106,71660250034.7979,74176113089.9494,74846483252.855,77427057199.6452,81136922903.7485,86968791133.6781,88729162245.5733,89500341199.5419,95618110012.4831,102980110729.696,108775620349.079,114820142495.154,122779274838.914,130882706991.227,138941804505.723,144613635421.66,150762331265.362,156396451606.529,170381458377.611,170793065289.462,170676456703.649,172685547750.969,181516775970.153,189485207634.671,200478776258.219,212778307552.702,219288062091.01,222070086195.673,234321743781.76,246108571729.902,253141727649.947,261630083834.698,268431627288.425,275110410785.986
"Gambia, The",GMB,GDP at market prices (constant 2010 US$),NY.GDP.MKTP.KD,,,,,,,172511783.225106,172511783.225106,189031759.079121,193635670.825667,205551712.920038,205416301.549712,205912802.569875,224960414.777983,238185373.283037,267704708.609747,287384286.039778,297269087.137348,316045929.43624,311848260.60591,331401394.801694,342410197.885098,339792188.95895,376772546.824955,390092425.808086,386923842.888132,402753171.003884,412638073.361705,431111165.728129,456528281.016936,472775571.822219,487464894.429975,503934816.90202,519113842.885312,519915075.622107,524499937.233744,536162432.466683,562434386.788253,582119581.960865,619375231.226392,653440870.022485,691340442.024706,668871875.534639,714823372.065284,765218419.327008,758012541.800052,766533358.521271,794366380.48455,839920448.143372,894092762.494649,952429030.415536,911201531.483016,964618263.859891,1010735774.36954,1019604582.06133,
Italy,ITA,GDP at market prices (constant 2010 US$),NY.GDP.MKTP.KD,545587936045.8
"Hong Kong SAR, China",HKG,GDP at market prices (constant 2010 US$),NY.GDP.MKTP.KD,,,,,,17646914072.5316,17963587597.2928,18251600758.537,18871674770.8568,21012392496.6626,22946967034.0575,24620544326.6381,27233218366.4241,30577436438.9298,31315910641.5164,31470018825.6732,36556880968.4152,40843484682.3004,44217537723.3852,49327657046.3582,54313855535.2722,59343749332.4989,61094263256.6516,64745875473.9274,71203501724.2224,71742527987.2525,79674401051.0777,90349564237.6023,98039821040.139,100272275421.3,104113116514.092,110049570498.302,116911143429.477,124160923333.7,131655256011.867,134780527700.784,140520117876.574,147686148439.864,138998299558.026,142482530553.942,153401659211.88,154261939959.413,156817528193.178,161610386688.859,175670644204.052,188649442838.506,201916372094.71,214969758150.611,219544022644.222,214145185396.967,228637697575.04,239645861296.69,243720566257.359,251208086226.166,257775655510.28,263860579574.348

现在要测试GDP是否正在读取它们,我运行了以下方法,并且都返回了一个空数据框...知道为什么吗?

print GDP.where(GDP['Country Name'] == "Iran, Islamic Rep.").dropna() #NOT READ... .
print GDP.where(GDP['Country Name'] == "Hong Kong SAR, China").dropna() # NOT READ.. .

1 个答案:

答案 0 :(得分:0)

上述国家的GDP节省了。但是print语句中的查询不正确。

问题是,how方法中参数dropna的默认值为'any',这意味着将删除每一行,其中至少一个单元格为{ {1}}。如果将参数设置为NONE的方式将起作用,因为现在将仅删除行,其中每个单元格均为'all'

NONE

下面的代码行也应该起作用

 print (GDP.where(GDP['Country Name'] == "Country Name").dropna(how='all'))