variables in dictionaries in python -


i trying create dataframe using dictionary in have added variables values..

gpa_min = df_gpa.min() gpa_q1 = df_gpa.quantile(0.25) ratio_gpa = 'gpa ratio q1/outlier ', df_gpa.quantile(0.25)/df_gpa.min(), 'should be' gre_min = df_gre.min() gre_q1 = df_gre.quantile(0.25)    ratio_gre = 'gre ratio q1/outlier ', df_gre.quantile(0.25)/df_gre.min()  index = ['gre','gpa'] columns = ['min','q1','q1/min']   outlier = pd.dataframe({"gre": [gre_min,gre_q1,ratio_gre],                         "gpa": [gpa_min,gpa_q1,ratio_gpa]},                        index = index, columns = columns) print outlier 

this runs no error, answer data frame ´nan´ values... confusing, if called variables created above ('gre_min, gre_q1, ratio_gre, gpa_min, gpa_q1, ratio_gpa') values correctly

i using python 2.7

thanks!

building pandas dataframe way assume dictionary you're passing in dictionary of columns of dataframe... subsequent definition of index , columns inconsistent that. pandas tries smart, 'interpolates' data on provided indices/columns. except since has none (your 'data' columns , 'textual' columns unrelated: in example below, tries columns x, y , z columns gre , gpa), spits out nans

in[70]: pd.dataframe({'gre': [1,2,3], 'gpa': ['a', 'b', 'c']}, index=['gre', 'gpa'],           columns=['x', 'y', 'z']) out[70]:         x    y    z gre  nan  nan  nan gpa  nan  nan  nan 

flipping rows/columns gets want:

in[71]: pd.dataframe({'gre': [1,2,3], 'gpa': ['a', 'b', 'c']}, columns=['gre', 'gpa'],           index=['x', 'y', 'z']) out[71]:     gre gpa x    1   y    2   b z    3   c 

or simpler still, let infer column names dictionary keys:

in[72]: pd.dataframe({'gre': [1,2,3], 'gpa': ['a', 'b', 'c']}, index=['x', 'y', 'z']) out[72]:    gpa  gre x      1 y   b    2 z   c    3 

Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -