How to transpose full file with pandas

Viewed 60

I wanted to open a csv file, transpose (or swap) the rows and columns and then write only one column to a new file. The output file should be 73 rows long but every time I get this output:

Province/State        NaN
Country/Region    Lebanon
Lat               33.8547
Long              35.8623
1/22/20                 0
               ...   
3/26/20               368
3/27/20               391
3/28/20               412
3/29/20               438
3/30/20               446
Name: 147, Length: 73, dtype: object

This is the python code:

import pandas as pd
inp_file = pd.read_csv('input_file.csv')
out_file = inp_file.T
#I have also tried out_file=inp_file.transpose()
f = open("output_file.csv", "w")
f.write(str(out_file[147]))
f.close()

Is there a way to get the full original row as a column in the output file?

Thank you

1 Answers

I would use display maximum rows and then call the dataframe to print again

pd.set_option('display.max_rows',999)

print (f)
Related