0

I want to extract some data(specific columns) from a csv file and invert them to rows and create an other csv file. So I thought of converting the current csv file to a list or dict and then use loops to convert it to rows and write the new csv file. I have seen some topics on that using stringIO and so forth but in vain.

Is there a simpler way to get to my objective? If so, please tell me and if not please help in converting string to csv file. I am using Python 3.

SurvivalMachine
  • 7,946
  • 15
  • 57
  • 87
Jamie
  • 1
  • 4

1 Answers1

0
import pandas as pd
fields = ['star_name', 'ra']
df = pd.read_csv('data.csv',usecols=fields)
# if you want to invert values keeping columns fixed.
df.T # use transpose and pass to csv.
# for creating dict. 
df_dict = df.to_dict()