简体   繁体   中英

Cannot import the whole JSON file into Google Colab

I am trying to import a json file from github to google colab. It worked but it doesn't read all the columns from the file. Here is my code:

import pandas as pd
url = 'https://raw.githubusercontent.com/lequanngo/WorldHappiness/master/WorldHappiness.json'
df = pd.read_json(url, orient='columns')
df.head(10)

This is the result:

country||ladder||ladderSD||Positive_affect||Negative_affect||SocialSupport||Freedom
Finland| |1| |4| |41| |10| |2| |5| 
Denmark
Norway
etc

',country,ladder,ladder_sd,positive_affect,negative_affect,social_support,freedom,corruption,generosity,gdp_per_capita,healthy_life_expectancy,continent\n0,Finland,1,4,41,10,2,5,4,47,22,27,Europe\n1'

all 11 columns showed (country, ladder, ladder SD, positve_affect, negative_affect, etc). But When I get the descriptive statistics by using

df.describe()
      |ladder|  |ladderSD|
count  156       156
mean   78.5      78.5
std
min
25%

Only ladder and ladder SD were calculated. Positive_affect and negative_affect and all other columns for continuous data werent taken into account.

Can anyone please help me with this?

is this output what you expect?

>>> url = 'https://raw.githubusercontent.com/lequanngo/WorldHappiness/master/WorldHappiness.json'
>>> df = pd.read_json(url, orient='records', dtype='dict')
>>> df.head()                                                                                                                                                   

  Country (region)  Ladder  SD of Ladder Positive affect Negative affect  ... Freedom Corruption Generosity Log of GDP\nper capita Healthy life\nexpectancy
0          Finland       1             4              41              10  ...       5          4         47                     22                       27
1          Denmark       2            13              24              26  ...       6          3         22                     14                       23
2           Norway       3             8              16              29  ...       3          8         11                      7                       12
3          Iceland       4             9               3               3  ...       7         45          3                     15                       13
4      Netherlands       5             1              12              25  ...      19         12          7                     12                       18

[5 rows x 11 columns]

>>> df.describe()                                                                                                                                               

           Ladder  SD of Ladder
count  156.000000    156.000000
mean    78.500000     78.500000
std     45.177428     45.177428
min      1.000000      1.000000
25%     39.750000     39.750000
50%     78.500000     78.500000
75%    117.250000    117.250000
max    156.000000    156.000000

>>> df.describe(include='all')                                                                                                                                  

       Country (region)      Ladder  SD of Ladder  Positive affect  Negative affect  ...  Freedom  Corruption Generosity  Log of GDP\nper capita Healthy life\nexpectancy
count               156  156.000000    156.000000            156.0            156.0  ...    156.0         156      156.0                     156                      156
unique              156         NaN           NaN            156.0            156.0  ...    156.0         149      156.0                     153                      151
top               Nepal         NaN           NaN            155.0            155.0  ...    155.0                  155.0                                                 
freq                  1         NaN           NaN              1.0              1.0  ...      1.0           8        1.0                       4                        6
mean                NaN   78.500000     78.500000              NaN              NaN  ...      NaN         NaN        NaN                     NaN                      NaN
std                 NaN   45.177428     45.177428              NaN              NaN  ...      NaN         NaN        NaN                     NaN                      NaN
min                 NaN    1.000000      1.000000              NaN              NaN  ...      NaN         NaN        NaN                     NaN                      NaN
25%                 NaN   39.750000     39.750000              NaN              NaN  ...      NaN         NaN        NaN                     NaN                      NaN
50%                 NaN   78.500000     78.500000              NaN              NaN  ...      NaN         NaN        NaN                     NaN                      NaN
75%                 NaN  117.250000    117.250000              NaN              NaN  ...      NaN         NaN        NaN                     NaN                      NaN
max                 NaN  156.000000    156.000000              NaN              NaN  ...      NaN         NaN        NaN                     NaN                      NaN

[11 rows x 11 columns]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM