Ad

Issue To Add Value In A Dataframe

- 1 answer

I managed to do this :

works

It's a dict with pokemon's number in Keys, and number of victory (vary), name (name) as Values

It works and the Out is what I wanted. But as I want to make some visualization after, I felt like dict isn't the best. So I tried the same but to obtain a DataFrame :

doesnt

But as you can see, the Out is an empty df. The range is 0,10 to try before 0,800. I added prints to see where is the problem. I also tried the 2 #lines, same result.

I juste need something that fill my "brawldf".

It might be a basic issue but I can't manage to find the solution.

Ad

Answer

You're not assigning anything.

You can either use append with:

df = df.append({'ID': i}, {'name':name}, {'nbvictory':vary}, ignore_index=True)

or assign the new row with iloc to your DataFrame. See docs here

df.iloc[i] = [i, name, vary] 

*edit: sorry I forgot to add: ignore_index=True, edited my answer. This should work fine now.

Ad
source: stackoverflow.com
Ad