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: https://docs.google.com/spreadsheets/d/1eX5ShqSHYU…
_____________________________________________________________
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
mapping.keys()]
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!"
