Best writers. Best papers. Let professionals take care of your academic papers

Order a similar paper and get 15% discount on your first order with us
Use the following coupon "FIRST15"

Python: What am I doing wrong? Please fix my code?

Python: What am I doing wrong? Please fix my code?.

Need help with my Python question – I’m studying for my class.

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

Python: What am I doing wrong? Please fix my code?