python - 将元组列表转换为 Pandas 数据框的单列?

标签 python python-3.x pandas dataframe

我有一个像这样的元组列表:

list_t = [(1,2),(1,7),(1,8),(2,6),(5,8)]
我想制作数据框,但只有一列:
enter image description here
目前使用这个
df_com = pd.DataFrame(list_t,columns=["so","des"])
但后来我必须再次加入他们,因此增加了运营成本。
感谢您的帮助

最佳答案

将元组列表转换为 Series :

s = pd.Series(list_t)
print (s)
0    (1, 2)
1    (1, 7)
2    (1, 8)
3    (2, 6)
4    (5, 8)
dtype: object
对于 DataFrame 添加 Series.to_frame :
df = pd.Series(list_t).to_frame('new')
print (df)
      new
0  (1, 2)
1  (1, 7)
2  (1, 8)
3  (2, 6)
4  (5, 8)

关于python - 将元组列表转换为 Pandas 数据框的单列?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66782995/

相关文章:

Python:基于其他列表的字符串和无的排序列表?

python - Pandas 在相同事件但不同时间戳上展平时间序列数据帧

python - 如果在 Pandas 中的字符串末尾,则删除某些字符

python - 对于python 3,使用lxml在属性前面写入 'xsi:'

python - 寻找点对应的区间

python Holoviews 带有列的布局选项卡

python - 如何抑制上下文管理器中的给定异常?

python - 为什么 lineEdit 显示这样?

python - 反向 z 评分 Pandas 数据框

python - 我的字典计算字母而不是单词