python what am i doing wrong please fix my code

Here is my prompt:

  • Nested loops are going to be very helpful here.
  • With your dictionary of lists, writing to a CSV will be rather difficult.. but you can maybe make it easier if you transform the CSV into a different data structure first…
  • There should be 27 countries for Asia, 24 countries for Middle East, 4 countries for North America, 20 countries for Central America, 49 countries for Sub-Saharan Africa, 15 countries for Australia and Oceania, and 48 countries for Europe.

I’ve attached the appropriate csv:…

For this part you will be cross-referencing the data in the CSV file and the getting an output and writing it to a new CSV fi


This is what my code is but for some reason, it keeps saying SyntaxErrror: ‘ return’ outside function:

def mappingRegions(inputCsvFiles):

dataFrame = pd.read_csv(inputCsvFile)[[‘Region’, ‘Country’]]

regions = dataFrame[‘Region’.unique()]

mapping = {}

for region in ‘regions’:

mapping[‘Region’] = dataFrame[dataFrame.Region.eq(region)][‘Country’].unique()

dataFrames = [pd.DataFrame({key: mapping[key]}) for key in


dataFrame = pd.concat(dataFrames, axis=1)

dataFrame.to_csv(‘Countries_By_Region.csv’, index=False)

return mapping

"Looking for a Similar Assignment? Get Expert Help at an Amazing Discount!"
Looking for a Similar Assignment? Our Experts can help. Use the coupon code SAVE30 to get your first order at 30% off!

Hi there! Click one of our representatives below and we will get back to you as soon as possible.

Chat with us on WhatsApp