使用Python解析多个文件并将数据写入单个文件
我是Python编程新手,我正在尝试解析多个文件,从每个文件中获取数据并将其写入单个文件。我想要创建数据的一个文件就是基于主键及其关联数据的唯一数据(类似于我们在excel中创建透视表的方式)。我正在附加示例文本文件。所有文本文件都有三个部分,每个部分将被解析为一个单独的文本文件使用Python解析多个文件并将数据写入单个文件,python,Python,我是Python编程新手,我正在尝试解析多个文件,从每个文件中获取数据并将其写入单个文件。我想要创建数据的一个文件就是基于主键及其关联数据的唯一数据(类似于我们在excel中创建透视表的方式)。我正在附加示例文本文件。所有文本文件都有三个部分,每个部分将被解析为一个单独的文本文件 Test Data 123 Section1 PrimaryKey Primary Key2 Primary Key3 TestData1 TestData2 TestData3 Key1
Test Data 123
Section1
PrimaryKey Primary Key2 Primary Key3 TestData1 TestData2 TestData3
Key1 Data1 Sample1 119 100 0.920336134
Key1 Data2 Sample2 120 101 0.921666667
Key1 Data3 Sample3 115 96 0.914782609
Key2 Data1 Sample1 77 58 0.833246753
Key2 Data2 Sample2 66 47 0.792121212
Key3 Data1 Sample1 106 87 0.900754717
Section2
PrimaryKey Primary Key2 Primary Key3 TestData1 TestData2 TestData3 TestData4 TestData5 TestData6
Key1 Data1 Sample1 119 100 0.856 0.859 0.862 0.865
Key1 Data2 Sample2 120 101 0.876 0.879 0.882 0.885
Key1 Data3 Sample3 115 96 0.896 0.899 0.902 0.905
Key2 Data1 Sample1 77 58 0.916 0.919 0.922 0.925
Key2 Data2 Sample2 66 47 0.936 0.939 0.942 0.945
Key3 Data1 Sample1 106 87 0.956 0.959 0.962 0.965
Key1 Data1 Sample1 116 97 0.976 0.979 0.982 0.985
Key1 Data2 Sample2 101 82 0.996 0.999 1.002 1.005
Key1 Data3 Sample3 106 87 1.016 1.019 1.022 1.025
Key2 Data1 Sample1 61 42 1.036 1.039 1.042 1.045
Section3
Column1 Column2
Test1 DataTest
Test2 DataTest1
Test3 DataTest2
Test4 DataTest3
Test5 DataTest4
Test6 DataTest5
Test7 DataTest6
Test8 DataTest7
你有什么问题?你尝试过什么吗?如果你要旋转表格数据,你可能应该安装库;我试着读取文件,我可以解析每一行,这就是它停止的地方。我不知道如何在python中使用vlookup来对齐数据。DSM:我将查看pandas库。谢谢,你有没有试过只用一个dict来填写来自多个来源的数据?