Как удалить строку из списка, который содержит строковые значения и кадры данных? - PullRequest
0 голосов
/ 29 апреля 2020

У меня есть список, содержащий кадры данных и строковые значения. Я хочу сбросить только строковые значения. Когда я поместил list.remove («Объем импорта (% изменения)»), я получил: Значение истинности для DataFrame неоднозначно. Используйте a.empty, a.bool (), a.item (), a.any () или a.all (). Я хочу код в форме l oop для многих случаев. Как это обобщить? Заранее спасибо

   [    Country ISO3          Country Name  Indicator Id  \
     0            ABW                 Aruba           346   
     1            AFG           Afghanistan           346   
     2            AGO                Angola           346   
     3            ALB               Albania           346   
     4            ARE  United Arab Emirates           346   
     ..           ...                   ...           ...   
     167          VNM               Vietnam           346   
     168          YEM           Yemen, Rep.           346   
     169          ZAF          South Africa           346   
     170          ZMB                Zambia           346   
     171          ZWE              Zimbabwe           346   

                                  Indicator Subindicator Type    1980    1981  \
     0    Gross national savings (% of GDP)          % of GDP     NaN     NaN   
     1    Gross national savings (% of GDP)          % of GDP     NaN     NaN   
     2    Gross national savings (% of GDP)          % of GDP  17.704  15.105   
     3    Gross national savings (% of GDP)          % of GDP  27.121  39.852   
     4    Gross national savings (% of GDP)          % of GDP  45.757  43.159   
     ..                                 ...               ...     ...     ...   
     167  Gross national savings (% of GDP)          % of GDP  12.270   8.971   
     168  Gross national savings (% of GDP)          % of GDP     NaN     NaN   
     169  Gross national savings (% of GDP)          % of GDP  35.318  28.097   
     170  Gross national savings (% of GDP)          % of GDP  10.834   0.052   
     171  Gross national savings (% of GDP)          % of GDP     NaN     NaN   

            1982    1983    1984  ...    2015    2016    2017    2018    2019  \
     0       NaN     NaN     NaN  ...  15.466  17.221  17.044  18.203  19.872   
     1       NaN     NaN     NaN  ...  21.342  25.728  22.462  21.856  17.526   
     2    12.419  11.463  14.437  ...  28.491  24.487  23.351  21.906  15.947   
     3    41.023  44.479  46.845  ...  15.761  16.966  17.430  17.906  17.880   
     4    37.663  36.592  40.707  ...  30.666  30.850  28.508  29.248  29.572   
     ..      ...     ...     ...  ...     ...     ...     ...     ...     ...   
     167  10.955  11.829  12.266  ...  27.519  29.520  29.578  29.596  29.099   
     168     NaN     NaN     NaN  ...  -4.412  -1.366   1.956   5.084   6.783   
     169  22.165  26.711  23.121  ...  16.323  16.381  16.432  14.582  14.430   
     170  -0.655   6.240   7.016  ...  38.880  33.655  37.122  37.077  36.717   
     171     NaN     NaN     NaN  ...   6.416  14.803  14.976   7.603   5.251   

            2020    2021    2022    2023    2024  
     0    19.228  18.487  17.654  16.826  15.808  
     1    17.440  17.754  20.424  20.528  20.543  
     2    18.147  18.359  19.004  19.650  20.219  
     3    18.103  17.731  17.247  16.727  16.257  
     4    28.179  27.200  26.531  26.046  25.829  
     ..      ...     ...     ...     ...     ...  
     167  28.605  28.339  27.952  27.305  26.739  
     168   4.459   3.369   2.529   2.601   2.312  
     169  14.086  14.053  14.210  14.363  14.528  
     170  35.783  35.220  35.128  34.145  33.748  
     171   4.945   4.713   4.679   4.607     NaN  

     [172 rows x 50 columns],
         Country ISO3          Country Name  Indicator Id  \
     0            ABW                 Aruba           347   
     1            AFG           Afghanistan           347   
     2            AGO                Angola           347   
     3            ALB               Albania           347   
     4            ARE  United Arab Emirates           347   
     ..           ...                   ...           ...   
     187          WSM                 Samoa           347   
     188          YEM           Yemen, Rep.           347   
     189          ZAF          South Africa           347   
     190          ZMB                Zambia           347   
     191          ZWE              Zimbabwe           347   

                                   Indicator Subindicator Type     1980     1981  \
     0    Inflation, average consumer prices             Index      NaN      NaN   
     1    Inflation, average consumer prices             Index      NaN      NaN   
     2    Inflation, average consumer prices             Index      NaN      NaN   
     3    Inflation, average consumer prices             Index      NaN      NaN   
     4    Inflation, average consumer prices             Index   66.700   72.000   
     ..                                  ...               ...      ...      ...   
     187  Inflation, average consumer prices             Index   13.930   16.787   
     188  Inflation, average consumer prices             Index      NaN      NaN   
     189  Inflation, average consumer prices             Index    4.308    4.967   
     190  Inflation, average consumer prices             Index    0.005    0.006   
     191  Inflation, average consumer prices             Index  160.147  169.046   

             1982     1983     1984  ...     2015     2016     2017     2018  \
     0        NaN      NaN      NaN  ...  118.354  117.303  116.728  120.796   
     1        NaN      NaN      NaN  ...  101.296  105.736  110.998  111.693   
     2        NaN      NaN      NaN  ...  148.377  193.920  251.795  301.218   
     3        NaN      NaN      NaN  ...  100.000  101.282  103.295  105.390   
     4     77.100   78.100   80.000  ...  265.654  269.951  275.261  283.739   
     ..       ...      ...      ...  ...      ...      ...      ...      ...   
     187   19.859   23.128   25.871  ...  109.117  109.259  110.677  114.741   
     188      NaN      NaN      NaN  ...  498.322  435.717  543.184  770.088   
     189    5.683    6.392    7.117  ...   92.000   97.833  102.992  107.750   
     190    0.007    0.008    0.010  ...  155.818  183.660  195.740  209.525   
     191  170.043  155.671  152.780  ...   59.638   58.709   59.242   65.526   

             2019     2020      2021      2022      2023      2024  
     0    122.460  124.789   127.376   130.091   132.896   135.769  
     1    113.815  117.799   123.099   129.254   135.717   142.503  
     2    353.821  393.158   424.214   451.585   478.680   507.400  
     3    107.498  110.077   113.160   116.554   120.051   123.653  
     4    289.798  295.757   301.947   308.331   314.762   321.766  
     ..       ...      ...       ...       ...       ...       ...  
     187  120.639  125.766   130.168   133.813   137.560   141.411  
     188  924.105  993.413  1043.080  1095.240  1150.000  1207.500  
     189  113.090  119.198   125.754   132.670   139.967   147.666  
     190  232.049  259.895   286.534   315.188   346.707   381.377  
     191  113.638  124.281   128.880   132.746   136.728   140.830  

     ,'Volume of imports (% change)',
     'Volume of exports (% change)',
     'General government structural balance(% of GDP)',
     'General government net debt(% of GDP)']

1 Ответ

0 голосов
/ 29 апреля 2020

Я думаю, это то, что вы ищете. Фильтрует список для DataFrames.

input_list = [
    pandas.DataFrame(),
    pandas.DataFrame(),
    "test_string",
    "another_string"]

new_list = [list_entry for list_entry in input_list if type(list_entry) == pandas.DataFrame]
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...