Linked Questions

61 votes
6 answers
158k views

add a row at top in pandas dataframe [duplicate]

Below is my dataframe import pandas as pd df = pd.DataFrame({'name': ['jon','sam','jane','bob'], 'age': [30,25,18,26], 'sex':['male','male','female','male']}) age name ...
Shubham R's user avatar
  • 7,526
0 votes
2 answers
10k views

add new row to pandas dataframe [duplicate]

I am trying to add a new row to a dataframe. I know that it is usually done with dataframe.append() method but it will not work for my case. Why it does not work is because the user can read any csv ...
Mohammed Abdu's user avatar
2 votes
2 answers
434 views

Append new data to existing dataframe more efficiently - python [duplicate]

Is there a more efficient way to append new data to an existing dataframe? As per the following example, I'm importing an existing df (frame_orig). Then some more code is performed, which produces ...
jonboy's user avatar
  • 348
0 votes
0 answers
106 views

How to add a row into a dataframe? [duplicate]

I want to add a row at the end of my dataframe but it shows some error. data = data.loc[[0, 8, 11, 14, 18, 23, 41, 42, 43]] row = {'Department/Ministry': 'OTHERS', 'Fund alloted(in ?crores)': 592971....
Garima Gaur's user avatar
272 votes
3 answers
567k views

Error "'DataFrame' object has no attribute 'append'"

I am trying to append a dictionary to a DataFrame object, but I get the following error: AttributeError: 'DataFrame' object has no attribute 'append' As far as I know, DataFrame does have the method ...
Maksimjeet Chowdhary's user avatar
76 votes
7 answers
224k views

Is it possible to append Series to rows of DataFrame without making a list first?

I have some data I'm trying to organize into a DataFrame in Pandas. I was trying to make each row a Series and append it to the DataFrame. I found a way to do it by appending the Series to an empty ...
O.rka's user avatar
  • 30.5k
109 votes
4 answers
126k views

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

I have a DataFrame object similar to this one: onset length 1 2.215 1.3 2 23.107 1.3 3 41.815 1.3 4 61.606 1.3 ... What I would like to do is insert a row at a ...
Troas's user avatar
  • 1,217
3 votes
5 answers
1k views

How to keep column titles when inserting a sum row in Pandas dataframe

I have a dataframe: Name y1 y2 y3 1 Ben 01 02 03 2 Jane 04 05 06 3 Sarah 07 07 06 I am trying to add in a row in my dataframe ...
Alex's user avatar
  • 85
1 vote
5 answers
3k views

Is it possible to put the Pandas dataframe column header as a footer instead?

I have a numpy array, and for simplicity sake it is empty. The dimensions are 8x12 . I have my row and column headers defined. column = [_ for _ in 'ABCDEFGH'] row = list(range(12, 0, -1)) self.board ...
shelbaz's user avatar
  • 97
5 votes
2 answers
3k views

Pandas: Conditionally insert rows into DataFrame while iterating through rows

While iterating through the rows of a specific column in a Pandas DataFrame, I would like to add a new row below the currently iterated row, if the cell in the currently iterated row meets a certain ...
P A N's user avatar
  • 5,892
5 votes
3 answers
1k views

Split a string in pandas row and insert new rows by enlarging the dataframe

I have the following DataFrame: no word status 0 0 one to_check 1 1 two to_check 2 2 :) emoticon 3 3 dr. to_check 4 4 "future" to_check 5 5 to to_check 6 6 be to_check I want to ...
Taner Sezer's user avatar
0 votes
1 answer
5k views

Adding headers to a DataFrame with Pandas while dropping the index

I have a DataFrame that is resampled into a smaller DataFrame, which retained a datetimeindex. I transposed the dataframe and now wish to remove the dateindex and replace it with strings (labels), ...
Chris's user avatar
  • 1,327
1 vote
2 answers
2k views

copy columns name into first row of data in pandas

I have a pandas dataframe like following when I write this dataframe into google sheets I found out header is missing. My questions is how to make it work? or copy columns name into first row of data ...
jacobcan118's user avatar
  • 8,737
1 vote
1 answer
677 views

Python: concat rows of two dataframes where not all columns are the same

I have two dataframes: EDIT: df1 = pd.DataFrame(index = [0,1,2], columns=['timestamp', 'order_id', 'account_id', 'USD', 'CAD']) df1['timestamp']=['2022-01-01','2022-01-02','2022-01-03'] df1['...
MathMan 99's user avatar
0 votes
1 answer
841 views

How to insert rows into dataframes in pandas python?

I'm very new to pandas and dataframes. I have two lists in python which contains columns and values that needs to be inserted for that columns in a row. For Ex: col_list = ['column1', 'column3', '...
Tyrion Lannister's user avatar

15 30 50 per page