【问题标题】:python create a dataframe the same as the excel table [closed]python创建一个与excel表相同的数据框[关闭]
【发布时间】:2021-11-07 23:43:48
【问题描述】:

谁能帮我用python写下表?

另外,在 B1 和 B4 行中,我需要一个 Python 公式,将其放入上个月最后一个工作日。

其他都是字符串。

【问题讨论】:

    标签: python excel pandas dataframe


    【解决方案1】:

    确切地说,我不知道你的问题是什么。

    但是如果你想生成一个.csv文件(表格)你可以按照这个教程:https://www.pythontutorial.net/python-basics/python-write-csv-file/

    如果这是您的问题,您可以使用下面的代码示例:

    import csv
    
    last_mont = 'last month'
    last_b_day = 'last business day'
    
    rows = []
    rows.append(['Previous Month End Date:', f'formula for {last_mont} {last_b_day}?', 'Previous Month End Date:', '20210831'])
    rows.append([])
    rows.append(['check'])
    rows.append([])
    rows.append(['', 'report', 'report','Match?'])
    rows.append(['position', 'formula 1 goes here', 'formual 2 too', 'formula 1 = formual 2'])
    rows.append([])
    
    f = open('output.csv','w')
    writer = csv.writer(f)
    
    for row in rows:
        writer.writerow(row)
    
    f.close()
    

    它将生成这个 .csv 表:

    【讨论】:

      【解决方案2】:

      要读取 CSV 文件,您应该使用 pandas。

      import pandas as pd
      file = ‘path_to_file’
      df = pd.read_csv(file)
      print(df)
      

      read_csv 在熊猫中

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-12-23
        • 1970-01-01
        • 2016-12-11
        • 1970-01-01
        • 1970-01-01
        • 2019-08-09
        相关资源
        最近更新 更多