How can I transform the following DataFrame into one with cities as rows and each cuisine as a column, and 1 or 0 as values (1 if the city has that kind of cuisine)?
I think this turns out to be a very common problem in transforming data into features for machine learning.
I am aware of the Pandas pivot_table functionality, but it asks for a value column, and in this case we don't have any.
import pandas as pd
data = {
'city': ['NY','NY', 'SF','SF','SF'],
'cuisine': ['Japanese', 'Chinese', 'French', 'Japanse', 'German']
}
df = pd.DataFrame(data)