Reputation: 27
I have a dataframe in this format:
how
to
have
an
empty
first
row
How do i make it become this such that the first row is empty followed by my data afterwards:
#blank row (I dont want it to be None or "" or [], i just want it to be an empty row)
how
to
have
an
empty
first
row
Upvotes: 1
Views: 2047
Reputation: 2239
Here is another solution (Just change 'inserted' to '', for an empty string. If using numbers use np.nan):
pd.DataFrame(np.insert(df.values, 0, values=['inserted'], axis=0)).rename(columns ={0:'col1'})
col1
0 inserted
1 how
2 to
3 have
4 an
5 empty
6 first
7 row
You can set where (which row) you want the value to be inserted into:
pd.DataFrame(np.insert(df.values, 5, values=['inserted'], axis=0)).rename(columns ={0:'col1'})
col1
0 how
1 to
2 have
3 an
4 empty
5 inserted
6 first
7 row
Upvotes: 1
Reputation: 862671
I believe you need:
df = pd.DataFrame({'col':['']}).append(df, ignore_index=True)
print (df)
col
0
1 how
2 to
3 have
4 an
5 empty
6 first
7 row
Upvotes: 0