[英]Pandas - Concatenate values of lists into a single column in dataframe
I want to concatenate a list of nth entries into a single column in a pandas-data frame.我想将第 n 个条目的列表连接到熊猫数据框中的单个列中。
The number of entries of the list can variate.列表的条目数可以变化。
Sample Input:样本输入:
a = {"unix_group_A": [
"abc4034",
"abc7228",
"abc7231",
"abc7230",
"abc3555",
"abc7216"
],
"unix_group_B": [
"asdfasd4034",
"asdfasd7228",
"asdfasd7231",
"asdfasd7230",
"asdfasd3555",
"asdfasd7216",
"asdf"
]}
Output of: Output 的:
df_bla = pd.DataFrame.from_dict(a, orient='index')
[enter image description here][1]
Expected Output:预期 Output:
0 1
unix_group_A abc4034, abc7228, abc7231, abc7230, abc3555, abc7216
unix_group_B asdfasd4034, asdfasd7228, asdfasd7231, asdfasd7230, asdfasd3555, asdfasd7216, asdf
I couldn't find a question which fits my problem.我找不到适合我的问题的问题。
Thank you for your help.谢谢您的帮助。
Regards.问候。
try this,尝试这个,
pd.DataFrame([[k, ", ".join(v)] for k, v in a.items()])
0 1
0 unix_group_A abc4034, abc7228, abc7231, abc7230, abc3555, a...
1 unix_group_B asdfasd4034, asdfasd7228, asdfasd7231, asdfasd...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.