[英]lists that contain strings and numbers to excel and put each in its own cell
I have the following list:我有以下清单:
["Test1 10 15 Top Gain",
"Test2 11 12 Top Gain"
"Test3 12 15 Top Gain"]
and I want to take this from Python to excel and have it come up like this in excel.我想把它从 Python 带到 excel 并让它像这样在 excel 中出现。
A B C D
1 Test1 10 15 Top Gain
2 Test2 11 12 Top Gain
3 Test3 12 15 Top Gain
You can parse the list
data into dictionary format, then you can construct a dataframe
using dictionary.您可以将list
数据解析为字典格式,然后您可以使用字典构造一个dataframe
。 Once you have the dictionary, to_excel()
does the exporing.一旦你有了字典, to_excel()
进行曝光。
import pandas as pd
L = ["Test1 10 15 Top_Gain",
"Test2 11 12 Top_Gain",
"Test3 12 15 Top_Gain"]
data_dict = {}
for i, val in enumerate(L):
data_dict[i] = val.split()
data = pd.DataFrame(data_dict)
data = data.T
data.columns = ['A', 'B', 'C', 'D']
print(data)
# A B C D
# 0 Test1 10 15 Top_Gain
# 1 Test2 11 12 Top_Gain
# 2 Test3 12 15 Top_Gain
data.to_excel('MyExcelFile.xlsx')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.