(Apr-18-2022, 05:53 AM)dramauh Wrote: The dataframe looks like thisPost a working Dataframe and not a example you have put together.
(Apr-18-2022, 05:53 AM)dramauh Wrote: PD: I am aware that the code looks dirty.Yes if gone make this this mess the why use Pandas DataFrame in the first place?
Bye working DataFrame i mean like this,so this can you also just copy and run.
import pandas as pd data = { "Name": ["Jai", "Princi", "Gaurav", "Anuj"], "Height": [5.1, 6.2, 5.1, 5.2], "Qualification": ["Msc", "MA", "Msc", "Msc"], } df = pd.DataFrame(data) address = ["Delhi", "Bangalore", "Chennai", "Patna"] df["Address"] = addressShow DataFrame and some export examples.
>>> df Name Height Qualification Address 0 Jai 5.1 Msc Delhi 1 Princi 6.2 MA Bangalore 2 Gaurav 5.1 Msc Chennai 3 Anuj 5.2 Msc Patna >>> df.to_dict() {'Address': {0: 'Delhi', 1: 'Bangalore', 2: 'Chennai', 3: 'Patna'}, 'Height': {0: 5.1, 1: 6.2, 2: 5.1, 3: 5.2}, 'Name': {0: 'Jai', 1: 'Princi', 2: 'Gaurav', 3: 'Anuj'}, 'Qualification': {0: 'Msc', 1: 'MA', 2: 'Msc', 3: 'Msc'}} >>> df.to_csv(index=False) ('Name,Height,Qualification,Address\r\n' 'Jai,5.1,Msc,Delhi\r\n' 'Princi,6.2,MA,Bangalore\r\n' 'Gaurav,5.1,Msc,Chennai\r\n' 'Anuj,5.2,Msc,Patna\r\n') >>> df.to_string() (' Name Height Qualification Address\n' '0 Jai 5.1 Msc Delhi\n' '1 Princi 6.2 MA Bangalore\n' '2 Gaurav 5.1 Msc Chennai\n' '3 Anuj 5.2 Msc Patna') >>> print(df.to_xml()) <?xml version='1.0' encoding='utf-8'?> <data> <row> <index>0</index> <Name>Jai</Name> <Height>5.1</Height> <Qualification>Msc</Qualification> <Address>Delhi</Address> </row> <row> <index>1</index> <Name>Princi</Name> <Height>6.2</Height> <Qualification>MA</Qualification> <Address>Bangalore</Address> </row> <row> <index>2</index> <Name>Gaurav</Name> <Height>5.1</Height> <Qualification>Msc</Qualification> <Address>Chennai</Address> </row> <row> <index>3</index> <Name>Anuj</Name> <Height>5.2</Height> <Qualification>Msc</Qualification> <Address>Patna</Address> </row> </data>