Pandas: Printing all the values from an index

Advertisements

I am calculating concentrations from a file that has separate Date and Time columns. I set the date and time columns as indexes as they are not suppose to change. However when I print the new dataframe it only prints the "date" one time like this:

                      55... 
Date       Time                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
2020-12-30 10:37:04  0.000000 ...
           10:37:07  0.000000 ...
           10:37:10  0.000000 ...
           10:37:13  0.000000 ...
           10:37:16  0.000000 ...

What I need is for it to print the date for each row just like it is in the original dataframe. It should remain the same as the original dataframe date and time values. The original dataframe is:

Date    Time    Accum.  Scatter...
2020-12-30  10:37:04    3   0.789...
2020-12-30  10:37:07    3   0.814...
2020-12-30  10:37:10    3   0.787...
2020-12-30  10:37:13    3   0.803...
2020-12-30  10:37:16    3   0.798...
2020-12-30  10:37:19    3   0.818...
2020-12-30  10:37:22    3   0.809...

The code I have is :

df = pd.read_csv('UHSAS 20201230c.txt',delimiter=r'\s+',engine = 'python')
df.set_index(['Date', 'Time'],inplace=True)

concentration = df.iloc[:,13:].div(df.Sample,axis=0)

print(concentration.to_string())

I know it seems simple but I am new to pandas.
Thank you in advance.

>Solution :

remove inplace=True and replace it with reset_index() at the end

here is the code (first two lines)

df = pd.read_csv('csv2.txt',delimiter=r'\s+',engine = 'python')
df.set_index(['Date', 'Time'] ).reset_index()

# cannot do calculation step, as sample column is not present in the sample data
Date    Time    Accum.  Scatter...
0   2020-12-30  10:37:04    3   0.789...
1   2020-12-30  10:37:07    3   0.814...
2   2020-12-30  10:37:10    3   0.787...
3   2020-12-30  10:37:13    3   0.803...
4   2020-12-30  10:37:16    3   0.798...
5   2020-12-30  10:37:19    3   0.818...
6   2020-12-30  10:37:22    3   0.809...

Leave a ReplyCancel reply