[英]How to check if string elements of lists are in dataframe/other list (python)
[英]Python: list of lists and string to dataframe
我有一個具有以下格式的列表:
data = [
['string1', [a, b, c]],
['string2', [d, e, f]],
['string3', [g, h, i]],
['string4', [j, k, l]],
]
我想將它轉換成這樣的數據框,將字符串作為列名,將列表作為列內容:
string1 string2 string3 string4
a d g j
b e h k
c f i l
我怎樣才能做到這一點?
將值轉換為字典,然后轉換為DataFrame
構造函數:
df = pd.DataFrame(dict(data))
print (df)
string1 string2 string3 string4
0 a d g j
1 b e h k
2 c f i l
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.