Reputation: 61
I'd like to convert each cell of dataframe to list
import pandas as pd
a=[619, 200, 50, 45]
dic={"a":a}
df = pd.DataFrame.from_dict(dic)
#Output should be like this:
a
[619]
[200]
[50]
[45]
Upvotes: 4
Views: 1361
Reputation: 61930
Use:
df["a"] = df["a"].apply(lambda x: [x])
print(df)
Output
a
0 [619]
1 [200]
2 [50]
3 [45]
Or:
df["a"] = [[x] for x in df["a"]]
Upvotes: 4