如何将矩阵向下移动 1 行 1 列?
How can I move a matrix down by 1 row and 1 column?
我想知道如何将 excel 文件中的矩阵向下移动一行和一列,然后将这个新矩阵另存为同一目录中的新文件?
下面显示的是打开我的测试 excel 文件的程序:
import pandas as pd
main=pd.read_csv('C:/Users/Jonas/Desktop/testfile/testing.csv') #Reads the matrix in the excel file
测试文件包含一个 4x3 矩阵,在 spyder 中打开时它以某种方式显示为 3x3 矩阵?为什么也会发生这种情况。
谢谢。
发生这种情况是因为您的 CSV 文件中没有 header 行,但 Pandas 默认情况下需要一行。将 headers=None
添加到您的 read_csv
调用以解决此问题:
import pandas as pd
main=pd.read_csv('C:/Users/Jonas/Desktop/testfile/testing.csv', headers=None) #Reads the matrix in the excel file
我想知道如何将 excel 文件中的矩阵向下移动一行和一列,然后将这个新矩阵另存为同一目录中的新文件?
下面显示的是打开我的测试 excel 文件的程序:
import pandas as pd
main=pd.read_csv('C:/Users/Jonas/Desktop/testfile/testing.csv') #Reads the matrix in the excel file
测试文件包含一个 4x3 矩阵,在 spyder 中打开时它以某种方式显示为 3x3 矩阵?为什么也会发生这种情况。
谢谢。
发生这种情况是因为您的 CSV 文件中没有 header 行,但 Pandas 默认情况下需要一行。将 headers=None
添加到您的 read_csv
调用以解决此问题:
import pandas as pd
main=pd.read_csv('C:/Users/Jonas/Desktop/testfile/testing.csv', headers=None) #Reads the matrix in the excel file