如何在python ubuntu中从csv文件打印两列数据集

2024-10-02 02:37:06 发布

您现在位置:Python中文网/ 问答频道 /正文

我有包含13列的csv数据文件。我想拆分两个列值,另一个拆分另一个列来添加一个列。在

def rowfilter(col1, col2):
    try:
        csv_read = csv.reader(open('items.csv'), delimiter=',')
        for row in csv_read:
        print(row[int(cols[0]):int(cols[1])])  
    except FileNotFoundError:
        print("File not found")

    inputrows = input("Enter columns in the format: col1 col2 ")

    rowfilter(inputrows.split())) 

Tags: csvinread数据文件defcol2col1int
1条回答
网友
1楼 · 发布于 2024-10-02 02:37:06

要使用csv,通常最简单的方法是使用^{}模块。它提供易于使用的I/O、选择和操作接口。在

def rowfilter(col1, col2):
    try:
        df = pd.read_csv('items.csv')

        print(df[[col1, col2]])  
    except FileNotFoundError:
        print("File not found")

    inputrows = input("Enter columns in the format: col1 col2 ")

    rowfilter(inputrows.split())) 

这将打印列。在

相关问题 更多 >

    热门问题