“使用Pandas添加List”的版本间的差异

来自YTYZX有图有真相的百科
跳转至: 导航搜索
(创建页面,内容为“ 在Python中使用以下代码将循环生成的列表依次添加为DataFrame的一行,并导出到Excel表格里面。 import pandas as pd df = pd.DataFrame()...”)
 
第8行: 第8行:
 
  df.columns = ['自然数', '平方值']  # 给DataFrame添加columns
 
  df.columns = ['自然数', '平方值']  # 给DataFrame添加columns
 
  df.to_excel(r'C:\GITPythonLesson\num.xlsx',sheet_name='Sheet1',engine='openpyxl')
 
  df.to_excel(r'C:\GITPythonLesson\num.xlsx',sheet_name='Sheet1',engine='openpyxl')
 +
 +
 输出结果为下图:
 +
[[File:PandasAppendList1.png]]

2022年10月4日 (二) 19:55的版本

在Python中使用以下代码将循环生成的列表依次添加为DataFrame的一行,并导出到Excel表格里面。
import pandas as pd
df = pd.DataFrame()
for i in range(10):
    j = i**2
    list1 = i, j
    df = df.append(list1, ignore_index=True)
df.columns = ['自然数', '平方值']  # 给DataFrame添加columns
df.to_excel(r'C:\GITPythonLesson\num.xlsx',sheet_name='Sheet1',engine='openpyxl')
输出结果为下图:

PandasAppendList1.png