The list that I want to convert into a dataframe stores different data types in each cell:
[In] type(example_list)
[Out] list
[In] type(example_list[0])
[Out] list
[In] type(example_list[0][0])
[Out] str
[In] type(example_list[0][1])
[Out] tuple
[In] type(example_list[0][2])
[Out] tuple
[In] type(example_list[0][1][0])
[Out] list
And the tuple elements all have the following format:
[In] example_list[0][1]
[Out] ([array([200.85183333, 200.85183333, 200.85183333])], ['#c8c8c8'])
[In] type(example_list[0][1][0])
[Out] list
[In] type(example_list[0][1][1])
[Out] list
When I use the pd.DataFrame
function I end up with 3 columns, but I want to have 5 columns (that is, 2 columns from each tuple element).
When I run the following command:
df = pd.DataFrame(example_list, columns=['Name','PrimaryColors','SecondaryColors'])
df.to_csv('test.csv', sep=',')
This is what I get (outputting only the first row below):
E123 ([array([200.85183333, 200.85183333, 200.85183333])], ['#c8c8c8']) ([array([226.9, 226.9, 226.9])], ['#e2e2e2'])
How can I instead end up with 5 columns instead of 3 and have the dataframe follow the following format?
Name PrimaryColorRGB PrHEX SecondaryColorsRGB SecHEX
E123 200.85183333, 200.85183333, 200.85183333 #c8c8c8 226.9, 226.9, 226.9 #e2e2e2