I would need help saving the values my for-loop iterates over.
With this script I create my csv the way I need it, but there is no information what value w and c has in each row. How can I add this information in two more columns?
import pandas as pd
df = pd.read_csv(...)
country_list = df.Country.unique()
wave_list = df.Wave.unique()
dn = pd.DataFrame()
for w in wave_list:
print ("Wave is: " + str(w))
wave_select =df[df["Wave"] == w] # Select Rows for Waves
for c in country_list:
print ("Country is: " + str(c))
country_select = df[df["Country"] == c] # Select Rows for Countries
out = country_select["Sea"].value_counts(normalize=True)*100 # Calculate Percentage
print (out)
dn = dn.append(out)
dn.to_csv (...)
I would be very grateful for help.