Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Pandas: Printing all the values from an index

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 :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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...
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading