Friday, 15 January 2010

python - NaN values when new column added to pandas DataFrame -



python - NaN values when new column added to pandas DataFrame -

hello , in advance. i'm trying generate new column in pandas dataframe equals values in pandas dataframe. when effort create new column nans new column values.

first utilize api phone call data, , 'mydata' dataframe 1 column of info indexed dates

mydata = quandl.get(["yahoo/index_mxx.4"], trim_start="2001-04-01", trim_end="2014-03-31", collapse="monthly")

the next dataframe csv next code, , contains many columns of info same number of rows 'mydata'

dwdata = pandas.dataframe.from_csv("filename", header=0, sep=',', index_col=0, parse_dates=true, infer_datetime_format=true)

i seek generate new column this:

dwdata['mxx'] = mydata.iloc[:,0]

again, nan values. can help me understand why it's doing , how resolve? i've read looks might have wrong indexes. indexes dates in each dataframe, 'mydata' have end-of-month dates while 'dwdata' has beginning-of-month dates. give thanks again.

because indexes not equal, nans result. either 1 or both of indexes must changed match. example:

mydata = mydata.set_index(dwdata.index)

the above alter index of 'mydata' dataframe match index of 'dwdata' dataframe.

since number of rows equal 2 dataframes, can pass values of 'mydata' new 'dwdata' column:

dwdata['mxx'] = mydata.iloc[:,0].values

python pandas dataframes nan

No comments:

Post a Comment