Home > other >  A very hurt about dataframe assignment problem
A very hurt about dataframe assignment problem

Time:12-11

1, I built a aa=pd. The DataFrame ();
2, then the loop statement:
Aa=aa + 100
No error, finally see the value of the aa NaN,
A mystery! Please master!!!!!! What should I do is right?
(I feel like a python dataframe is difficult to understand)

CodePudding user response:

Aa you is just a empty form, no lines, no columns, aa plus what you?
 aa=pd. DataFrame ({' a ': [3, 8],' b ': [4, 6],}) 
Aa=aa + 200
Print (aa)

CodePudding user response:

Pandas in the DataFrame is a kind of framework; Initialized to null, empty, here is Not 0, so aa=aa + 100, meaningless, NaN, Not a Number, generally represent infinity, or nonnumeric, I think this is the latter

If you want to give all data on the form 100, must first be initialized to its

CodePudding user response:

I'm wrong:
I defined the number of columns and the column aa=pd. The DataFrame (columns=[0, 1])
Then in a loop:
Aa. Loc [k, 0]=aa. The loc [k, 0] + 100
K=k + 1
The last column 0 aa content is NaN

CodePudding user response:

 import pandas as pd 
The import numpy as np


Aa=pd. DataFrame (np) random) randn (6, 2), the columns=[0, 1])
Print (aa)
Aa. The loc (1, 0]=aa. The loc [1, 0] + 100
Print (aa)

CodePudding user response:

Thank you very much, but have new problems again, I add some points, bother to guide
  • Related