I am running python program which takes csv data as string, need to sort it and return output as string
input= "Bet,Charle,Daniell,Ada,Eri\n17945,10091,10088,3907,10132\n2,12,13,48,11"
desired output = "Ada,Bet,Charle,Daniell,Eri\n3907,17945,10091,10088,10132\n48,2,12,13,11"
import pandas as pd
from io import StringIO
def sort_csv(input):
str_data = StringIO(input)
output_df = pd.read_csv(str_data, sep=",")
output_df = output_df.sort_index(axis=1)
output_df.to_csv(path_or_buf='temp.csv', index=False)
data = open('temp.csv').read()
return data
I am facing below error TypeError: slice indices must be integers or None or have an index method
pandas package is upgraded, using python 3.4. Any help?