I have a dataframe
import pandas as pd
d = { "letter": ["a", "b", "c"]}
df = pd.DataFrame(d)
if I use df.values.tolist()
, I will get
BUT my expected result is below
letter =['a','b','c']
which without the brackets
I have a dataframe
import pandas as pd
d = { "letter": ["a", "b", "c"]}
df = pd.DataFrame(d)
if I use df.values.tolist()
, I will get
BUT my expected result is below
letter =['a','b','c']
which without the brackets
You want to use the to_list()
function after indexing the column of interest:
import pandas as pd
d = { "letter": ["a", "b", "c"]}
df = pd.DataFrame(d)
# Call to_list() in column of interest
letter = df.letter.to_list()
letter
variable now holds:
['a', 'b', 'c']
import pandas as pd
d = { "letter": ["a", "b", "c"]}
df = pd.DataFrame(d)
df["letter"].values.tolist()
Output:
['a', 'b', 'c']
import pandas as pd
d = { "letter": ["a", "b", "c"]}
df = pd.DataFrame(d)
df.values.ravel().tolist()
['a', 'b', 'c']
if you print below then it'll be clear
print(df.values)
array([['a'],
['b'],
['c']], dtype=object)