-3

I have a csv file mentioned as below screen shot ...

enter image description here

and i want to convert the whole file in the below format in python.

enter image description here

Jitesh Vacheta
  • 85
  • 1
  • 13

2 Answers2

1

You can try this after reading your CSV file correct file path.

import pandas as pd
df = pd.read_csv("path/to/file", names=["Sentence", "Value"])
result = [(row["Sentence"], row["Value"]) for index, row in df.iterrows()]
print(result)
0

It's a single line using apply() method of dataframe

df.apply(lambda x: x.tolist(), axis=1)

OR

df.values.tolist() will also work

bigbounty
  • 16,526
  • 5
  • 37
  • 65