这是我自己在 Pandas 中的第一个程序,我正在尝试按列和行执行一些 csv 操作。我有一个包含多个文件的转换存储库。过渡存储库不断向其中添加文件。我正在尝试动态读取文件并执行一些操作并写入另一个文件夹中的主 csv 文件。
输入
1. Folder_1: `Transition_Data`
Test_1.csv, Test_2.csv
Nos,Time,Count Nos,Time,Count
------------------- ------------------
2341,12:00:00,9865 1234,12:30:00,7865
7352,12:00:00,8969 8435,12:30:00,7649
2. Folder2: Data_repository:Master_2.csv
Nos,00:00:00
------------
1234,1000
8435,5243
2341,563
7352,345
3.Expected Output
Nos,00:00:00,12:00:00,12:30:00
----------------------------------
1234,1000,0,6865
8435,5243,0,2406
2341,563,9302,0
7352,345,8624,0
Nos
从 transition_data 文件中读取列并检查其Nos
位置。每次Master_2.csv
创建一个带有新标题的新列,如果填充了数据间隙,则减去Transition_data 文件的填充新创建的列中的新值。我确实尝试了几个例子,但我搞砸了。Time
col[2]
col[1]
Master_2.csv
0
程序更新如下所述,现在在路由文件读取和写入的逻辑时遇到问题
import pandas as pd
import os
import numpy as np
import glob
path_1 = '/Transition_Data/'
path_2 = 'Data_repository/Master_2.csv'
df_1 = pd.DataFrame(dict(Nos=Nos, Time=Time, Count=Count))
pivot = pd.pivot_table(path_1, '/.*CSV, index='Nos', columns='Time', values='Count')
df_master = pd.DataFrame('Master_2.csv', {'Nos':, '00:00:00':}).set_index('Nos')
result = df_master.join(pivot, how='inner')
result[result.columns[1:]] = result[result.columns[1:]].sub(result[result.columns[0]], axis=0)
result.fillna(0)
我尝试了上面的程序并得到了以下错误
Traceback (most recent call last):
File "read_test.py", line 19, in <module>
df = pd.read_csv(filename, header='Count')
File "/usr/lib/python2.7/dist-packages/pandas/io/parsers.py", line 420, in parser_f
return _read(filepath_or_buffer, kwds)
File "/usr/lib/python2.7/dist-packages/pandas/io/parsers.py", line 218, in _read
parser = TextFileReader(filepath_or_buffer, **kwds)
File "/usr/lib/python2.7/dist-packages/pandas/io/parsers.py", line 502, in __init__
self._make_engine(self.engine)
File "/usr/lib/python2.7/dist-packages/pandas/io/parsers.py", line 610, in _make_engine
self._engine = CParserWrapper(self.f, **self.options)
File "/usr/lib/python2.7/dist-packages/pandas/io/parsers.py", line 972, in __init__
self._reader = _parser.TextReader(src, **kwds)
File "parser.pyx", line 476, in pandas.parser.TextReader.__cinit__ (pandas/parser.c:4538)
TypeError: an integer is required