python - ValueError when trying to add row to dataframe -
i trying add row df[0] = [0,360, 0, 0, 0,2,3.9,100.01,100,0]
dataframe df
shown below error valueerror: length of values not match length of index
. have no idea why is, there 10 values in row , there 10 columns.
dt months_to_maturity asset_id orig_iss_dt \ 1 2016-02-15 6 (binary data) 1986-02-18 00:00:00.0 2 2016-08-01 12 (binary data) 1986-08-01 00:00:00.0 3 2017-02-06 18 (binary data) 1987-02-06 00:00:00.0 maturity_dt pay_freq_cd coupon closing_price face_value \ 1 2016-02-15 00:00:00.0 2 9.250 105.40625 100 2 2016-08-01 00:00:00.0 2 9.380 105.86200 100 3 2017-02-06 00:00:00.0 2 8.450 111.42610 100 dt2 1 1970-01-01 00:00:00.000000002 2 1970-01-01 00:00:00.000000002 3 1970-01-01 00:00:00.000000002
thank you
because
df[0] = ...
is syntax adding column, not row, , should array on right should of same length columns, i.e. number of rows (or scalar). if want add row do
df.loc[0] = <values>
i guess part of confusion comes fact sort of opposite numpy syntax, in sense a[0] = <values>
assigns values zeroth row rather column.
Comments
Post a Comment