Advertisement
gregwa

FCM142 - Kidswords

Jan 8th, 2019
524
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 9.27 KB | None | 0 0
  1. # ======================================================
  2. # Script for FCM 142 - February 2019
  3. # Written by G.D. Walters
  4. # Version #2
  5. # ======================================================
  6.  
  7. import pandas as pd
  8. # Change the path to where your data actually is, or leave the path off all together
  9. # and keep the data in the same folder as the code.
  10. csvfile = '/home/greg/Downloads/WhenDoChildrenLearnWords/main_data.csv'
  11. rawdata = pd.read_csv(csvfile)
  12. # Create our beginning basic DataFrame
  13. df = pd.DataFrame(rawdata)
  14. print('========================================================')
  15. print(' Number of cells with bad data by column....            ')
  16. print('========================================================')
  17. # Now, find out how many fields in each column has 'bad' data.
  18. print(df.isnull().sum(axis=0))
  19. # and hold so the data can be seen...
  20. print('Make sure your terminal is pretty wide so you can see all the data that comes next')
  21. print('(about 160 characters wide if possible), and then')
  22. keyin = input('Press <Enter> to continue -> ')
  23.  
  24. # now, create a list of the columns that we are actually interested in right now.
  25. cols_to_use = ['Word_NW','Translation','AoA','VSoA','Lex_cat','Freq','CDS_freq']
  26. # Create another DataFrame with just the columns we want...
  27. # NOTE: DataFrame df is unchanged
  28. print('========================================================')
  29. print(' Our new DataFrame with just the columns of interest    ')
  30. print('========================================================')
  31.  
  32. df2 = df[cols_to_use]
  33. print(df2)
  34. # Set the DataFrame to 'is_copy' so we don't get any warning messages...
  35. # df2.is_copy = False
  36. # However, this is a depreciated command and might not work in
  37. # the future, near or otherwise
  38. pd.set_option('mode.chained_assignment', None)
  39. print('========================================================')
  40. print(' Cleaning the data....                                  ')
  41. print('========================================================')
  42.  
  43. # Next we cleans the data by filling numeric values with a mean of thos columns
  44. # and 'unknown' in the text field
  45. df2['AoA'].fillna(df2['AoA'].mean(),inplace=True)
  46. df2['AoA'].fillna(df2['AoA'].mean(),inplace=True)
  47. df2['VSoA'].fillna(df2['VSoA'].mean(),inplace=True)
  48. df2['Freq'].fillna(df2['Freq'].mean(),inplace=True)
  49. df2['CDS_freq'].fillna(df2['CDS_freq'].mean(),inplace=True)
  50. df2['Lex_cat'].fillna('unknown',inplace=True)
  51.  
  52. # And check to make sure that everything is filled...
  53. print('========================================================')
  54. print(' Number of cells STILL with bad data by column....      ')
  55. print('========================================================')
  56.  
  57. print(df2.isnull().sum(axis=0))
  58. keyin = input('Press <Enter> to continue -> ')
  59.  
  60. # Now, select just the rows where AoA is less than 18 months of age
  61. # will return 21 rows
  62. print('========================================================')
  63. print(' Data of column AoA less than 18 (months) ....          ')
  64. print('========================================================')
  65.  
  66. print(df2[df2.AoA < 18])
  67. keyin = input('Press <Enter> to continue -> ')
  68. # Now, display same data, but sorted by 'A0A' ascending
  69. print('========================================================')
  70. print(' Same data sorted by AoA ascending....                  ')
  71. print('========================================================')
  72.  
  73. print(df2[df2.AoA < 18].sort_values('AoA',ascending=True))
  74. keyin = input('Press <Enter> to continue -> ')
  75.                                                # ~ Word_NW    Translation   AoA  VSoA           Lex_cat      Freq  CDS_freq
  76. # ~ 370                                         'en mamma'        'mommy'  12.0  20.0            people   36751.0     171.0
  77. # ~ 409                                             'takk'    'thank you'  13.0  40.0  games & routines  106589.0     106.0
  78. # ~ 2                                     'brrr (bil-lyd)'        'vroom'  13.0  20.0     sound effects       NaN      20.0
  79. # ~ 8                                          'nam - nam'      'yum yum'  13.0  40.0     sound effects      35.0      19.0
  80. # ~ 394                                              'hei'           'hi'  13.0  40.0  games & routines   64086.0      74.0
  81. # ~ 379                                         'en pappa'        'daddy'  13.0  20.0            people   24689.0     118.0
  82. # ~ 391                                            'hadet'          'bye'  14.0  40.0  games & routines     467.0       6.0
  83. # ~ 1                                                'bææ'      'baa baa'  15.0  40.0     sound effects      18.0       5.0
  84. # ~ 401  'Borte! (lek hvor ansikt gjemmes og plutselig ...   'peek-a-boo'  15.0  40.0  games & routines       5.0      27.0
  85. # ~ 397                                               'ja'          'yes'  15.0  40.0  games & routines  158496.0    3291.0
  86. # ~ 7                                                'møø'          'moo'  15.0  40.0     sound effects       8.0       7.0
  87. # ~ 11                                         'voff voff'    'woof woof'  15.0  40.0     sound effects      10.0      52.0
  88. # ~ 404                                              'nei'           'no'  15.0  40.0  games & routines  136554.0     470.0
  89. # ~ 0                                                 'au'         'ouch'  16.0  40.0     sound effects    4366.0       7.0
  90. # ~ 70                                           'en ball'         'ball'  16.0  40.0      common nouns   96368.0      74.0
  91. # ~ 387                                           'å bade'        'bathe'  17.0  60.0  games & routines    8123.0      16.0
  92. # ~ 91                                          'en banan'       'banana'  17.0  60.0      common nouns    4673.0      17.0
  93. # ~ 6                                               'mjau'         'meow'  17.0  60.0     sound effects     214.0       7.0
  94. # ~ 3                                          'gakk gakk'  'quack quack'  17.0  40.0     sound effects      16.0       3.0
  95. # ~ 350                                          'en baby'         'baby'  17.0  60.0            people   16739.0      33.0
  96. # ~ 110                                               'is'    'ice cream'  17.0  60.0      common nouns  180159.0      11.0
  97. # Now sort first by 'AoA' then by 'VSoA'
  98. # When they first learn the word and the "average" number of words they know at this point
  99. print('========================================================')
  100. print(' Finally same data sorted by AoA then VSoA Ascending....')
  101. print('========================================================')
  102.  
  103. print(df2[df2.AoA < 18].sort_values(['AoA','VSoA'],ascending=True))
  104. keyin = input('Press <Enter> to continue -> ')
  105.                                                # ~ Word_NW    Translation   AoA  VSoA           Lex_cat      Freq  CDS_freq
  106. # ~ 370                                         'en mamma'        'mommy'  12.0  20.0            people   36751.0     171.0
  107. # ~ 2                                     'brrr (bil-lyd)'        'vroom'  13.0  20.0     sound effects       NaN      20.0
  108. # ~ 379                                         'en pappa'        'daddy'  13.0  20.0            people   24689.0     118.0
  109. # ~ 8                                          'nam - nam'      'yum yum'  13.0  40.0     sound effects      35.0      19.0
  110. # ~ 394                                              'hei'           'hi'  13.0  40.0  games & routines   64086.0      74.0
  111. # ~ 409                                             'takk'    'thank you'  13.0  40.0  games & routines  106589.0     106.0
  112. # ~ 391                                            'hadet'          'bye'  14.0  40.0  games & routines     467.0       6.0
  113. # ~ 1                                                'bææ'      'baa baa'  15.0  40.0     sound effects      18.0       5.0
  114. # ~ 7                                                'møø'          'moo'  15.0  40.0     sound effects       8.0       7.0
  115. # ~ 11                                         'voff voff'    'woof woof'  15.0  40.0     sound effects      10.0      52.0
  116. # ~ 397                                               'ja'          'yes'  15.0  40.0  games & routines  158496.0    3291.0
  117. # ~ 401  'Borte! (lek hvor ansikt gjemmes og plutselig ...   'peek-a-boo'  15.0  40.0  games & routines       5.0      27.0
  118. # ~ 404                                              'nei'           'no'  15.0  40.0  games & routines  136554.0     470.0
  119. # ~ 0                                                 'au'         'ouch'  16.0  40.0     sound effects    4366.0       7.0
  120. # ~ 70                                           'en ball'         'ball'  16.0  40.0      common nouns   96368.0      74.0
  121. # ~ 3                                          'gakk gakk'  'quack quack'  17.0  40.0     sound effects      16.0       3.0
  122. # ~ 6                                               'mjau'         'meow'  17.0  60.0     sound effects     214.0       7.0
  123. # ~ 91                                          'en banan'       'banana'  17.0  60.0      common nouns    4673.0      17.0
  124. # ~ 110                                               'is'    'ice cream'  17.0  60.0      common nouns  180159.0      11.0
  125. # ~ 350                                          'en baby'         'baby'  17.0  60.0            people   16739.0      33.0
  126. # ~ 387                                           'å bade'        'bathe'  17.0  60.0  games & routines    8123.0      16.0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement