csv gota数据框架:如何通过索引删除一行?

b5buobof  于 12个月前  发布在  Go
关注(0)|答案(1)|浏览(111)

假设我使用gota的dataframe.ReadCSV读取一个csv文件;我如何从这个 Dataframe 中删除第i行?文档中有一个删除列而不是行的函数。

dnph8jn4

dnph8jn41#

您可以使用select:

// df := dataframe.ReadCSV(/*your io variable*/)
   // I use this example
   df := dataframe.LoadRecords(
        [][]string{
            []string{"A", "B", "C", "D"},
            []string{"a", "4", "5.1", "true"},
            []string{"k", "5", "7.0", "true"},
            []string{"k", "4", "6.0", "true"},
            []string{"a", "2", "7.1", "false"},
        },
    )

    fmt.Println("Original dataframe:")
    fmt.Println(df)
    
    // only select A, B, C
    // and update df
    df = df.Select([]int{0, 1, 2}) // []string{"A", "B", "C",}

    fmt.Println("Updated dataframe:")
    fmt.Println(df)

注意:如果可以的话,不要使用这个包,因为这个包不支持!
Github repo是这样说的:This is an implementation of DataFrames, Series and data wrangling methods for the Go programming language. The API is still in flux so use at your own risk.
更好的方法是在python中使用pandas

相关问题