I want to import csv file that consist of country names to python. Csv file example:
Afghanistan
Albania
Algeria
I tried using these two pieces of code:
import pandas as pd
df = pd.read_csv('COUNTRIES_LIST.csv')
country_list = df.values.tolist()
print(country_list)
and
import csv
with open('file.csv', newline='') as f:
reader = csv.reader(f)
country_list = list(reader)
print(country_list)
Both of these give me a list, but the list has square brackets around each value like this:
[['Afghanistan'], ['Albania'], ['Algeria']]
This doesn't work for me because i'd need to change the values of the list to dictionaries, and for some reason the code that im using only works if there are no brackets in the values.
Is there a way to either import the list without the brackets or delete the brackets from the list? Also, if it's not practical to do that what kind file should i use in place of csv? Thanks!