I am new to Pandas and I would like to play with random text data. I am trying to add 2 new columns to a DataFrame df that will be populated with the key (newcol1) + value (newcol2) randomly selected from the dictionary.
countries = {'Africa':'Ghana','Europe':'France','Europe':'Greece','Asia':'Vietnam','Europe':'Lithuania'}
My df already has 2 columns, and I would like something like this:
Year Approved Continent Country
0 2016 Yes Africa Ghana
1 2016 Yes Europe Lithuania
2 2017 No Europe Greece
I can, of course, use a for or while loop to populate df ['Continent'] and df ['Country'], but I feel .apply () and np.random.choice can provide a simpler and more convenient solution for this.
source
share