python - Is it possible to insert a row at an arbitrary position in a dataframe using pandas? -


i have dataframe object similar one:

       onset    length 1      2.215    1.3 2     23.107    1.3 3     41.815    1.3 4     61.606    1.3 ... 

what insert row @ position specified index value , update following indices accordingly. e.g.:

       onset    length 1      2.215    1.3 2     23.107    1.3 3     30.000    1.3  # new row 4     41.815    1.3 5     61.606    1.3 ... 

what best way this?

you slice , use concat want.

line = dataframe({"onset": 30.0, "length": 1.3}, index=[3]) df2 = concat([df.ix[:2], line, df.ix[3:]]).reset_index(drop=true) 

this produce dataframe in example output. far i'm aware, concat best method achieve insert type operation in pandas, admittedly i'm no means pandas expert.


Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -