i want to convert this Dataframe into list of list
Year Sales Expenses Profit
2014 1000 400 200
2015 1170 460 250
2016 660 1120 300
2017 1030 540 350
this is the expected output
[
['Year', 'Sales', 'Expenses', 'Profit'],
['2014', 1000, 400, 200],
['2015', 1170, 460, 250],
['2016', 660, 1120, 300],
['2017', 1030, 540, 350]
]
Try using:
print([df.columns.tolist()] + df.values.tolist())
Output:
[['Year', 'Sales', 'Expenses', 'Profit'], [2014, 1000, 400, 200], [2015, 1170, 460, 250], [2016, 660, 1120, 300], [2017, 1030, 540, 350]]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With