Home > Software engineering >  Python Pandas Dataframe manipulation (Excel File)
Python Pandas Dataframe manipulation (Excel File)

Time:11-26

I'm fairly new to Python and I have a issue with dataframe manipulation using EXCEL:

This is a snippet of the excel:

Excel Snippet

I was able to drop the duplicates for datetime rows, and get a dataframe with only the datatime rows and another with only the descriptions;

I was able to drop the last row as well:

drop duplicates

What I wanted to do is to 'shift' the column A with dates to column B for the row above.

If both Dataframes were 1-1 its easy, but I have a row (in yellow) that does not have any datetime below.

Anyone has any idea how to do it?

To be something like this> enter image description here

    df_cdms_labour = pd.read_excel(test_cdms,
                               header=None,
                               names=['start_date', 'end_date', 'price','percent',
                                      'comment','rate',  'rate_comment','number_1','markup','markup_number'])

    df_cdms_labour.drop(df_cdms_labour.tail().index,inplace=True)
    df_cdms_labour

    def get_rate_text(df):
    return(df.loc[4,'start_date']     
    )

    def get_rates(df):
    flt = df.loc[:,'start_date'].apply(lambda x: isinstance(x, datetime))
    return(df[flt]
           .drop_duplicates()
           .reset_index(drop=True))
    rates = get_rates(df_cdms_labour)

CodePudding user response:

Here is a proposition using standard enter image description here

  • Related