I have a DataFrame df
like so:
0 1 2 3 4 5 ... 1154161
1 a b c d e f ... A
2 g h i j k l ... B
3 m n o p q r ... C
...
86405 Q V W X Y Z ... ZY
Which is a 86405 rows × 1154161 columns
DataFrame. Notice that the index starts from 1
. I am trying to assign a row with index=0
:
df.loc[0] = 0
But I run into error:
MemoryError: Unable to allocate 372. GiB for an array with shape (99725281205,) and data type float32
I want it to look like:
0 1 2 3 4 5 ... 1154161
0 0 0 0 0 0 0 ... 0 <--- add this row
1 a b c d e f ... A
2 g h i j k l ... B
3 m n o p q r ... C
...
86405 Q V W X Y Z ... ZY
Is there another way to assign without running out of memory? Maybe in chunks (preferably not)?
EDIT: Add DataFrame info as per @hpaulj request.
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 1154161 entries, 0 to 1154160
Columns: 86405 entries, 1 to 86405
dtypes: float32(86405)
memory usage: 371.5 GB
EDIT2: note that the letters in the sample DataFrame are actually numbers (float32) in reality