I am trying to create a script in Python to be used with Notepad 's PythonScript plugin. So far I've gotten Pandas working correctly in the environment and I've read in a CSV and sorted it the way I desired, the end goal is to remove all of the text in Notepad (which I know how to work with at this point) and write in the text from my Pandas sorted CSV.
The issue is that when I write the text from that CSV to the console to check it, Pandas has reformated my CSV to make it easier to look at, it removes all of the quotes from the fields and adjusts the tab sizes (my files are tab delimited, with some tabs having different length). I need my CSV to be the exactly the same just sorted differently, If anyone can help it would be greatly appreciated.
Some statements I'm using:
(csv is a String containing all of the text in my CSV file)
panda_csv = pd.read_csv(csv, sep="\t")
sorted = panda_csv.sort_values(by=["Name"], ascending=True, inplace=False)
console.write(sorted.to_string())
CodePudding user response:
I think you are looking to use to_csv instead of to_string.
CodePudding user response:
Since your original file seems to be tab-delimited, you can use the following to write output with a tab separator.
sorted.to_csv('output.csv', sep ='\t')