I am relatively new to Python (worked in R for awhile), and I feel that I am fundamentally misunderstanding something here about Python. Below is a minimal reproducible example, and in it, I would like the data frame with each integer as a variable. The function I write below will output only the "2" integer as a variable. If I tab the "return df" then I get the "0" integer as a variable and its contents as observations. If I use print and tab it, so that it occurs under the "df," I get what I want, but it's not in a data frame. Can someone explain what is going on here?
Expected output would be:
d = {0: ([1.5, 2.3, 4.5]), 1: ([5.6, 2.4, 4.4]), 2: ([3.5, 3.4, 5])}
def classify(z):
for i in z:
df = pd.DataFrame({i: z[i]})
return df
classify(d)