concatenate pandas rows if next row has NaN in specific columnAdd one row to pandas DataFrameSelecting multiple columns in a pandas dataframeRenaming columns in pandasAdding new column to existing DataFrame in Python pandasDelete column from pandas DataFrame by column nameHow to drop rows of Pandas DataFrame whose value in certain columns is NaNHow do I get the row count of a Pandas dataframe?How to iterate over rows in a DataFrame in Pandas?Select rows from a DataFrame based on values in a column in pandasGet list from pandas DataFrame column headers

Did 'Cinema Songs' exist during Hiranyakshipu's time?

Could the museum Saturn V's be refitted for one more flight?

Unlock My Phone! February 2018

What are the G forces leaving Earth orbit?

How exploitable/balanced is this homebrew spell: Spell Permanency?

Why was Sir Cadogan fired?

Sums of two squares in arithmetic progressions

How to stretch the corners of this image so that it looks like a perfect rectangle?

Knowledge-based authentication using Domain-driven Design in C#

How to compactly explain secondary and tertiary characters without resorting to stereotypes?

Am I breaking OOP practice with this architecture?

Is it a bad idea to plug the other end of ESD strap to wall ground?

How do I exit BASH while loop using modulus operator?

Standard deduction V. mortgage interest deduction - is it basically only for the rich?

Send out email when Apex Queueable fails and test it

Label inside tikzcd square

When handwriting 黄 (huáng; yellow) is it incorrect to have a disconnected 草 (cǎo; grass) radical on top?

Why is it a bad idea to hire a hitman to eliminate most corrupt politicians?

Mathematica command that allows it to read my intentions

What reasons are there for a Capitalist to oppose a 100% inheritance tax?

What is the opposite of "eschatology"?

Can I hook these wires up to find the connection to a dead outlet?

Why do I get negative height?

What is the most common color to indicate the input-field is disabled?



concatenate pandas rows if next row has NaN in specific column


Add one row to pandas DataFrameSelecting multiple columns in a pandas dataframeRenaming columns in pandasAdding new column to existing DataFrame in Python pandasDelete column from pandas DataFrame by column nameHow to drop rows of Pandas DataFrame whose value in certain columns is NaNHow do I get the row count of a Pandas dataframe?How to iterate over rows in a DataFrame in Pandas?Select rows from a DataFrame based on values in a column in pandasGet list from pandas DataFrame column headers













2















I have csv file parsed from pdf file and it is not correctly parsed as the table in pdf file has multiple rows.
importing it into pd DataFrame looks like this.



 Record Operational Address BIC
2 2007-03-03 Omladinskih Brigada 90V 11070 BEOGRAD SERBIA, AAAARSBG
3 NaN REPUBLIC OF NaN
4 1994-03-07 SAFAT ALI AL SALEM STREET, MUBARAKIA AAACKWKW
5 NaN OPPOSITE PUBLIC LIBRARY 13022 KUWAIT NaN
6 NaN KUWAIT NaN
7 2006-06-03 CHEZ NSM 3, AVENUE HOCHE 75008 PARIS AAADFRP1
8 NaN FRANCE NaN
9 2006-06-03 10 RUE DU COLISEE 75008 PARIS FRANCE AAAGFRP1
10 NaN NaN NaN
11 2014-07-05 152, 6TH OF SEPTEMBER BLVD. BUSINESS AAAJBG21
12 NaN CENTER LEGIS 4000 PLOVDIV BULGARIA NaN
13 1989-03-29 DHABAB STREET HEAD OFFICE BUILDING 11431 AAALSARI
14 NaN RIYADH SAUDI ARABIA NaN


I want to concatenate next rows into current row if next value in Record column is NaN.



I mean I want to get



 Record Operational Address BIC
2 2007-03-03 Omladinskih Brigada 90V 11070 BEOGRAD SERBIA, REPUBLIC OF AAAARSBG
4 1994-03-07 SAFAT ALI AL SALEM STREET, MUBARAKIA OPPOSITE PUBLIC LIBRARY 13022 KUWAIT KUWAIT AAACKWKW
7 2006-06-03 CHEZ NSM 3, AVENUE HOCHE 75008 PARIS FRANCE AAADFRP1
9 2006-06-03 10 RUE DU COLISEE 75008 PARIS FRANCE AAAGFRP1
11 2014-07-05 152, 6TH OF SEPTEMBER BLVD. BUSINESS CENTER LEGIS 4000 PLOVDIV BULGARIA AAAJBG21
13 1989-03-29 DHABAB STREET HEAD OFFICE BUILDING 11431 RIYADH SAUDI ARABIA AAALSARI


here is dataframe



import numpy a np
data = 'Record': 2: '2007-03-03',
3: np.NaN,
4: '1994-03-07',
5: np.NaN,
6: np.NaN,
7: '2006-06-03',
8: np.NaN,
9: '2006-06-03',
10: np.NaN,
11: '2014-07-05',
12: np.NaN,
13: '1989-03-29',
14: np.NaN,
'Operational Address': 2: 'Omladinskih Brigada 90V 11070 BEOGRAD SERBIA,',
3: 'REPUBLIC OF',
4: 'SAFAT ALI AL SALEM STREET, MUBARAKIA',
5: 'OPPOSITE PUBLIC LIBRARY 13022 KUWAIT',
6: 'KUWAIT',
7: 'CHEZ NSM 3, AVENUE HOCHE 75008 PARIS',
8: 'FRANCE',
9: '10 RUE DU COLISEE 75008 PARIS FRANCE',
10: np.NaN,
11: '152, 6TH OF SEPTEMBER BLVD. BUSINESS',
12: 'CENTER LEGIS 4000 PLOVDIV BULGARIA',
13: 'DHABAB STREET HEAD OFFICE BUILDING 11431',
14: 'RIYADH SAUDI ARABIA',
'BIC': 2: 'AAAARSBG',
3: np.NaN,
4: 'AAACKWKW',
5: np.NaN,
6: np.NaN,
7: 'AAADFRP1',
8: np.NaN,
9: 'AAAGFRP1',
10: np.NaN,
11: 'AAAJBG21',
12: np.NaN,
13: 'AAALSARI',
14: np.NaN

df = pd.DataFrame(data=data)









share|improve this question
























  • Is keeping the original index important, or can that just be a new index?

    – ALollz
    Mar 7 at 21:22











  • @ALollz No index is not important. There can be new index.

    – user2958481
    Mar 7 at 21:23















2















I have csv file parsed from pdf file and it is not correctly parsed as the table in pdf file has multiple rows.
importing it into pd DataFrame looks like this.



 Record Operational Address BIC
2 2007-03-03 Omladinskih Brigada 90V 11070 BEOGRAD SERBIA, AAAARSBG
3 NaN REPUBLIC OF NaN
4 1994-03-07 SAFAT ALI AL SALEM STREET, MUBARAKIA AAACKWKW
5 NaN OPPOSITE PUBLIC LIBRARY 13022 KUWAIT NaN
6 NaN KUWAIT NaN
7 2006-06-03 CHEZ NSM 3, AVENUE HOCHE 75008 PARIS AAADFRP1
8 NaN FRANCE NaN
9 2006-06-03 10 RUE DU COLISEE 75008 PARIS FRANCE AAAGFRP1
10 NaN NaN NaN
11 2014-07-05 152, 6TH OF SEPTEMBER BLVD. BUSINESS AAAJBG21
12 NaN CENTER LEGIS 4000 PLOVDIV BULGARIA NaN
13 1989-03-29 DHABAB STREET HEAD OFFICE BUILDING 11431 AAALSARI
14 NaN RIYADH SAUDI ARABIA NaN


I want to concatenate next rows into current row if next value in Record column is NaN.



I mean I want to get



 Record Operational Address BIC
2 2007-03-03 Omladinskih Brigada 90V 11070 BEOGRAD SERBIA, REPUBLIC OF AAAARSBG
4 1994-03-07 SAFAT ALI AL SALEM STREET, MUBARAKIA OPPOSITE PUBLIC LIBRARY 13022 KUWAIT KUWAIT AAACKWKW
7 2006-06-03 CHEZ NSM 3, AVENUE HOCHE 75008 PARIS FRANCE AAADFRP1
9 2006-06-03 10 RUE DU COLISEE 75008 PARIS FRANCE AAAGFRP1
11 2014-07-05 152, 6TH OF SEPTEMBER BLVD. BUSINESS CENTER LEGIS 4000 PLOVDIV BULGARIA AAAJBG21
13 1989-03-29 DHABAB STREET HEAD OFFICE BUILDING 11431 RIYADH SAUDI ARABIA AAALSARI


here is dataframe



import numpy a np
data = 'Record': 2: '2007-03-03',
3: np.NaN,
4: '1994-03-07',
5: np.NaN,
6: np.NaN,
7: '2006-06-03',
8: np.NaN,
9: '2006-06-03',
10: np.NaN,
11: '2014-07-05',
12: np.NaN,
13: '1989-03-29',
14: np.NaN,
'Operational Address': 2: 'Omladinskih Brigada 90V 11070 BEOGRAD SERBIA,',
3: 'REPUBLIC OF',
4: 'SAFAT ALI AL SALEM STREET, MUBARAKIA',
5: 'OPPOSITE PUBLIC LIBRARY 13022 KUWAIT',
6: 'KUWAIT',
7: 'CHEZ NSM 3, AVENUE HOCHE 75008 PARIS',
8: 'FRANCE',
9: '10 RUE DU COLISEE 75008 PARIS FRANCE',
10: np.NaN,
11: '152, 6TH OF SEPTEMBER BLVD. BUSINESS',
12: 'CENTER LEGIS 4000 PLOVDIV BULGARIA',
13: 'DHABAB STREET HEAD OFFICE BUILDING 11431',
14: 'RIYADH SAUDI ARABIA',
'BIC': 2: 'AAAARSBG',
3: np.NaN,
4: 'AAACKWKW',
5: np.NaN,
6: np.NaN,
7: 'AAADFRP1',
8: np.NaN,
9: 'AAAGFRP1',
10: np.NaN,
11: 'AAAJBG21',
12: np.NaN,
13: 'AAALSARI',
14: np.NaN

df = pd.DataFrame(data=data)









share|improve this question
























  • Is keeping the original index important, or can that just be a new index?

    – ALollz
    Mar 7 at 21:22











  • @ALollz No index is not important. There can be new index.

    – user2958481
    Mar 7 at 21:23













2












2








2








I have csv file parsed from pdf file and it is not correctly parsed as the table in pdf file has multiple rows.
importing it into pd DataFrame looks like this.



 Record Operational Address BIC
2 2007-03-03 Omladinskih Brigada 90V 11070 BEOGRAD SERBIA, AAAARSBG
3 NaN REPUBLIC OF NaN
4 1994-03-07 SAFAT ALI AL SALEM STREET, MUBARAKIA AAACKWKW
5 NaN OPPOSITE PUBLIC LIBRARY 13022 KUWAIT NaN
6 NaN KUWAIT NaN
7 2006-06-03 CHEZ NSM 3, AVENUE HOCHE 75008 PARIS AAADFRP1
8 NaN FRANCE NaN
9 2006-06-03 10 RUE DU COLISEE 75008 PARIS FRANCE AAAGFRP1
10 NaN NaN NaN
11 2014-07-05 152, 6TH OF SEPTEMBER BLVD. BUSINESS AAAJBG21
12 NaN CENTER LEGIS 4000 PLOVDIV BULGARIA NaN
13 1989-03-29 DHABAB STREET HEAD OFFICE BUILDING 11431 AAALSARI
14 NaN RIYADH SAUDI ARABIA NaN


I want to concatenate next rows into current row if next value in Record column is NaN.



I mean I want to get



 Record Operational Address BIC
2 2007-03-03 Omladinskih Brigada 90V 11070 BEOGRAD SERBIA, REPUBLIC OF AAAARSBG
4 1994-03-07 SAFAT ALI AL SALEM STREET, MUBARAKIA OPPOSITE PUBLIC LIBRARY 13022 KUWAIT KUWAIT AAACKWKW
7 2006-06-03 CHEZ NSM 3, AVENUE HOCHE 75008 PARIS FRANCE AAADFRP1
9 2006-06-03 10 RUE DU COLISEE 75008 PARIS FRANCE AAAGFRP1
11 2014-07-05 152, 6TH OF SEPTEMBER BLVD. BUSINESS CENTER LEGIS 4000 PLOVDIV BULGARIA AAAJBG21
13 1989-03-29 DHABAB STREET HEAD OFFICE BUILDING 11431 RIYADH SAUDI ARABIA AAALSARI


here is dataframe



import numpy a np
data = 'Record': 2: '2007-03-03',
3: np.NaN,
4: '1994-03-07',
5: np.NaN,
6: np.NaN,
7: '2006-06-03',
8: np.NaN,
9: '2006-06-03',
10: np.NaN,
11: '2014-07-05',
12: np.NaN,
13: '1989-03-29',
14: np.NaN,
'Operational Address': 2: 'Omladinskih Brigada 90V 11070 BEOGRAD SERBIA,',
3: 'REPUBLIC OF',
4: 'SAFAT ALI AL SALEM STREET, MUBARAKIA',
5: 'OPPOSITE PUBLIC LIBRARY 13022 KUWAIT',
6: 'KUWAIT',
7: 'CHEZ NSM 3, AVENUE HOCHE 75008 PARIS',
8: 'FRANCE',
9: '10 RUE DU COLISEE 75008 PARIS FRANCE',
10: np.NaN,
11: '152, 6TH OF SEPTEMBER BLVD. BUSINESS',
12: 'CENTER LEGIS 4000 PLOVDIV BULGARIA',
13: 'DHABAB STREET HEAD OFFICE BUILDING 11431',
14: 'RIYADH SAUDI ARABIA',
'BIC': 2: 'AAAARSBG',
3: np.NaN,
4: 'AAACKWKW',
5: np.NaN,
6: np.NaN,
7: 'AAADFRP1',
8: np.NaN,
9: 'AAAGFRP1',
10: np.NaN,
11: 'AAAJBG21',
12: np.NaN,
13: 'AAALSARI',
14: np.NaN

df = pd.DataFrame(data=data)









share|improve this question
















I have csv file parsed from pdf file and it is not correctly parsed as the table in pdf file has multiple rows.
importing it into pd DataFrame looks like this.



 Record Operational Address BIC
2 2007-03-03 Omladinskih Brigada 90V 11070 BEOGRAD SERBIA, AAAARSBG
3 NaN REPUBLIC OF NaN
4 1994-03-07 SAFAT ALI AL SALEM STREET, MUBARAKIA AAACKWKW
5 NaN OPPOSITE PUBLIC LIBRARY 13022 KUWAIT NaN
6 NaN KUWAIT NaN
7 2006-06-03 CHEZ NSM 3, AVENUE HOCHE 75008 PARIS AAADFRP1
8 NaN FRANCE NaN
9 2006-06-03 10 RUE DU COLISEE 75008 PARIS FRANCE AAAGFRP1
10 NaN NaN NaN
11 2014-07-05 152, 6TH OF SEPTEMBER BLVD. BUSINESS AAAJBG21
12 NaN CENTER LEGIS 4000 PLOVDIV BULGARIA NaN
13 1989-03-29 DHABAB STREET HEAD OFFICE BUILDING 11431 AAALSARI
14 NaN RIYADH SAUDI ARABIA NaN


I want to concatenate next rows into current row if next value in Record column is NaN.



I mean I want to get



 Record Operational Address BIC
2 2007-03-03 Omladinskih Brigada 90V 11070 BEOGRAD SERBIA, REPUBLIC OF AAAARSBG
4 1994-03-07 SAFAT ALI AL SALEM STREET, MUBARAKIA OPPOSITE PUBLIC LIBRARY 13022 KUWAIT KUWAIT AAACKWKW
7 2006-06-03 CHEZ NSM 3, AVENUE HOCHE 75008 PARIS FRANCE AAADFRP1
9 2006-06-03 10 RUE DU COLISEE 75008 PARIS FRANCE AAAGFRP1
11 2014-07-05 152, 6TH OF SEPTEMBER BLVD. BUSINESS CENTER LEGIS 4000 PLOVDIV BULGARIA AAAJBG21
13 1989-03-29 DHABAB STREET HEAD OFFICE BUILDING 11431 RIYADH SAUDI ARABIA AAALSARI


here is dataframe



import numpy a np
data = 'Record': 2: '2007-03-03',
3: np.NaN,
4: '1994-03-07',
5: np.NaN,
6: np.NaN,
7: '2006-06-03',
8: np.NaN,
9: '2006-06-03',
10: np.NaN,
11: '2014-07-05',
12: np.NaN,
13: '1989-03-29',
14: np.NaN,
'Operational Address': 2: 'Omladinskih Brigada 90V 11070 BEOGRAD SERBIA,',
3: 'REPUBLIC OF',
4: 'SAFAT ALI AL SALEM STREET, MUBARAKIA',
5: 'OPPOSITE PUBLIC LIBRARY 13022 KUWAIT',
6: 'KUWAIT',
7: 'CHEZ NSM 3, AVENUE HOCHE 75008 PARIS',
8: 'FRANCE',
9: '10 RUE DU COLISEE 75008 PARIS FRANCE',
10: np.NaN,
11: '152, 6TH OF SEPTEMBER BLVD. BUSINESS',
12: 'CENTER LEGIS 4000 PLOVDIV BULGARIA',
13: 'DHABAB STREET HEAD OFFICE BUILDING 11431',
14: 'RIYADH SAUDI ARABIA',
'BIC': 2: 'AAAARSBG',
3: np.NaN,
4: 'AAACKWKW',
5: np.NaN,
6: np.NaN,
7: 'AAADFRP1',
8: np.NaN,
9: 'AAAGFRP1',
10: np.NaN,
11: 'AAAJBG21',
12: np.NaN,
13: 'AAALSARI',
14: np.NaN

df = pd.DataFrame(data=data)






python pandas dataframe






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 7 at 21:16









ALollz

16k31738




16k31738










asked Mar 7 at 21:02









user2958481user2958481

148111




148111












  • Is keeping the original index important, or can that just be a new index?

    – ALollz
    Mar 7 at 21:22











  • @ALollz No index is not important. There can be new index.

    – user2958481
    Mar 7 at 21:23

















  • Is keeping the original index important, or can that just be a new index?

    – ALollz
    Mar 7 at 21:22











  • @ALollz No index is not important. There can be new index.

    – user2958481
    Mar 7 at 21:23
















Is keeping the original index important, or can that just be a new index?

– ALollz
Mar 7 at 21:22





Is keeping the original index important, or can that just be a new index?

– ALollz
Mar 7 at 21:22













@ALollz No index is not important. There can be new index.

– user2958481
Mar 7 at 21:23





@ALollz No index is not important. There can be new index.

– user2958481
Mar 7 at 21:23












1 Answer
1






active

oldest

votes


















1














Use cumsum to form groups and specify a dictionary for aggregation for each column.



agg_d = 'Record': 'first', 
'Operational Address': lambda x: ' '.join(x.dropna()),
'BIC': 'first'

df.groupby(df.Record.notnull().cumsum().rename(None)).agg(agg_d)

Record Operational Address BIC
1 2007-03-03 Omladinskih Brigada 90V 11070 BEOGRAD SERBIA, REPUBLIC OF AAAARSBG
2 1994-03-07 SAFAT ALI AL SALEM STREET, MUBARAKIA OPPOSITE PUBLIC LIBRARY 13022 KUWAIT KUWAIT AAACKWKW
3 2006-06-03 CHEZ NSM 3, AVENUE HOCHE 75008 PARIS FRANCE AAADFRP1
4 2006-06-03 10 RUE DU COLISEE 75008 PARIS FRANCE AAAGFRP1
5 2014-07-05 152, 6TH OF SEPTEMBER BLVD. BUSINESS CENTER LEGIS 4000 PLOVDIV BULGARIA AAAJBG21
6 1989-03-29 DHABAB STREET HEAD OFFICE BUILDING 11431 RIYADH SAUDI ARABIA AAALSARI





share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55052731%2fconcatenate-pandas-rows-if-next-row-has-nan-in-specific-column%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    Use cumsum to form groups and specify a dictionary for aggregation for each column.



    agg_d = 'Record': 'first', 
    'Operational Address': lambda x: ' '.join(x.dropna()),
    'BIC': 'first'

    df.groupby(df.Record.notnull().cumsum().rename(None)).agg(agg_d)

    Record Operational Address BIC
    1 2007-03-03 Omladinskih Brigada 90V 11070 BEOGRAD SERBIA, REPUBLIC OF AAAARSBG
    2 1994-03-07 SAFAT ALI AL SALEM STREET, MUBARAKIA OPPOSITE PUBLIC LIBRARY 13022 KUWAIT KUWAIT AAACKWKW
    3 2006-06-03 CHEZ NSM 3, AVENUE HOCHE 75008 PARIS FRANCE AAADFRP1
    4 2006-06-03 10 RUE DU COLISEE 75008 PARIS FRANCE AAAGFRP1
    5 2014-07-05 152, 6TH OF SEPTEMBER BLVD. BUSINESS CENTER LEGIS 4000 PLOVDIV BULGARIA AAAJBG21
    6 1989-03-29 DHABAB STREET HEAD OFFICE BUILDING 11431 RIYADH SAUDI ARABIA AAALSARI





    share|improve this answer



























      1














      Use cumsum to form groups and specify a dictionary for aggregation for each column.



      agg_d = 'Record': 'first', 
      'Operational Address': lambda x: ' '.join(x.dropna()),
      'BIC': 'first'

      df.groupby(df.Record.notnull().cumsum().rename(None)).agg(agg_d)

      Record Operational Address BIC
      1 2007-03-03 Omladinskih Brigada 90V 11070 BEOGRAD SERBIA, REPUBLIC OF AAAARSBG
      2 1994-03-07 SAFAT ALI AL SALEM STREET, MUBARAKIA OPPOSITE PUBLIC LIBRARY 13022 KUWAIT KUWAIT AAACKWKW
      3 2006-06-03 CHEZ NSM 3, AVENUE HOCHE 75008 PARIS FRANCE AAADFRP1
      4 2006-06-03 10 RUE DU COLISEE 75008 PARIS FRANCE AAAGFRP1
      5 2014-07-05 152, 6TH OF SEPTEMBER BLVD. BUSINESS CENTER LEGIS 4000 PLOVDIV BULGARIA AAAJBG21
      6 1989-03-29 DHABAB STREET HEAD OFFICE BUILDING 11431 RIYADH SAUDI ARABIA AAALSARI





      share|improve this answer

























        1












        1








        1







        Use cumsum to form groups and specify a dictionary for aggregation for each column.



        agg_d = 'Record': 'first', 
        'Operational Address': lambda x: ' '.join(x.dropna()),
        'BIC': 'first'

        df.groupby(df.Record.notnull().cumsum().rename(None)).agg(agg_d)

        Record Operational Address BIC
        1 2007-03-03 Omladinskih Brigada 90V 11070 BEOGRAD SERBIA, REPUBLIC OF AAAARSBG
        2 1994-03-07 SAFAT ALI AL SALEM STREET, MUBARAKIA OPPOSITE PUBLIC LIBRARY 13022 KUWAIT KUWAIT AAACKWKW
        3 2006-06-03 CHEZ NSM 3, AVENUE HOCHE 75008 PARIS FRANCE AAADFRP1
        4 2006-06-03 10 RUE DU COLISEE 75008 PARIS FRANCE AAAGFRP1
        5 2014-07-05 152, 6TH OF SEPTEMBER BLVD. BUSINESS CENTER LEGIS 4000 PLOVDIV BULGARIA AAAJBG21
        6 1989-03-29 DHABAB STREET HEAD OFFICE BUILDING 11431 RIYADH SAUDI ARABIA AAALSARI





        share|improve this answer













        Use cumsum to form groups and specify a dictionary for aggregation for each column.



        agg_d = 'Record': 'first', 
        'Operational Address': lambda x: ' '.join(x.dropna()),
        'BIC': 'first'

        df.groupby(df.Record.notnull().cumsum().rename(None)).agg(agg_d)

        Record Operational Address BIC
        1 2007-03-03 Omladinskih Brigada 90V 11070 BEOGRAD SERBIA, REPUBLIC OF AAAARSBG
        2 1994-03-07 SAFAT ALI AL SALEM STREET, MUBARAKIA OPPOSITE PUBLIC LIBRARY 13022 KUWAIT KUWAIT AAACKWKW
        3 2006-06-03 CHEZ NSM 3, AVENUE HOCHE 75008 PARIS FRANCE AAADFRP1
        4 2006-06-03 10 RUE DU COLISEE 75008 PARIS FRANCE AAAGFRP1
        5 2014-07-05 152, 6TH OF SEPTEMBER BLVD. BUSINESS CENTER LEGIS 4000 PLOVDIV BULGARIA AAAJBG21
        6 1989-03-29 DHABAB STREET HEAD OFFICE BUILDING 11431 RIYADH SAUDI ARABIA AAALSARI






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 7 at 21:28









        ALollzALollz

        16k31738




        16k31738





























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55052731%2fconcatenate-pandas-rows-if-next-row-has-nan-in-specific-column%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            AWS Lex not identifying response if by a variable The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) The Ask Question Wizard is Live! Data science time! April 2019 and salary with experienceEnforcing custom enumeration in AWS LEX for slot valuesHow to give response based on user response in Amazon Lex?Intercepting AWS Lambda Response to a AWS Lex QueryLex chat bot error: Reached second execution of fulfillment lambda on the same utteranceamazon lex showing invalid responseLambda response send back to Lex slot?Response card in Amazon lexAmazon Lex - Lambda response return HTML to botHow can I solve 424 (Failed Dependency) (python) obtained from Amazon lex?

            Алба-Юлія

            Захаров Федір Захарович