CSVデータを読み込む際に、不要な行を削除した上で読み込みたい。

前提

CSVデータを読み込んで、データ解析を試みようとしています。

実現したいこと

CSVデータには、最初の3行に余分なデータがあります。
この3行を削除したいと考えています。

発生している問題・エラーメッセージ


ParserError Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_1412/992268124.py in <module>
----> 1 An_Data = pd.read_csv('Target.csv', encoding="shift-jis")
2 An_Data[4:]

~\Anaconda3\lib\site-packages\pandas\util_decorators.py in wrapper(*args, **kwargs)
309 stacklevel=stacklevel,
310 )
--> 311 return func(*args, **kwargs)
312
313 return wrapper

~\Anaconda3\lib\site-packages\pandas\io\parsers\readers.py in read_csv(filepath_or_buffer, sep, delimiter, header, names, index_col, usecols, squeeze, prefix, mangle_dupe_cols, dtype, engine, converters, true_values, false_values, skipinitialspace, skiprows, skipfooter, nrows, na_values, keep_default_na, na_filter, verbose, skip_blank_lines, parse_dates, infer_datetime_format, keep_date_col, date_parser, dayfirst, cache_dates, iterator, chunksize, compression, thousands, decimal, lineterminator, quotechar, quoting, doublequote, escapechar, comment, encoding, encoding_errors, dialect, error_bad_lines, warn_bad_lines, on_bad_lines, delim_whitespace, low_memory, memory_map, float_precision, storage_options)
584 kwds.update(kwds_defaults)
585
--> 586 return _read(filepath_or_buffer, kwds)
587
588

~\Anaconda3\lib\site-packages\pandas\io\parsers\readers.py in _read(filepath_or_buffer, kwds)
486
487 with parser:
--> 488 return parser.read(nrows)
489
490

~\Anaconda3\lib\site-packages\pandas\io\parsers\readers.py in read(self, nrows)
1045 def read(self, nrows=None):
1046 nrows = validate_integer("nrows", nrows)
-> 1047 index, columns, col_dict = self._engine.read(nrows)
1048
1049 if index is None:

~\Anaconda3\lib\site-packages\pandas\io\parsers\c_parser_wrapper.py in read(self, nrows)
221 try:
222 if self.low_memory:
--> 223 chunks = self._reader.read_low_memory(nrows)
224 # destructive to chunks
225 data = _concatenate_chunks(chunks)

~\Anaconda3\lib\site-packages\pandas_libs\parsers.pyx in pandas._libs.parsers.TextReader.read_low_memory()

~\Anaconda3\lib\site-packages\pandas_libs\parsers.pyx in pandas._libs.parsers.TextReader._read_rows()

~\Anaconda3\lib\site-packages\pandas_libs\parsers.pyx in pandas._libs.parsers.TextReader._tokenize_rows()

~\Anaconda3\lib\site-packages\pandas_libs\parsers.pyx in pandas._libs.parsers.raise_parser_error()

ParserError: Error tokenizing data. C error: Expected 2 fields in line 4, saw 13

該当のソースコード

python

An_Data = pd.read_csv('Target.csv', encoding="shift-jis")An_Data[4:]

試したこと

最初の3行を削除するコードを作りましたが、そもそもその3行の影響で読み込めませんでした。
なので、読み込む際に4行目から読み込むことを指定しましたが、うまくいきません。

補足情報(CSVデータの中身)

"データ単位","分単位"
"開始日時","2022/08/01 14:00"
"終了日時","2022/08/31 16:00"
"Signal Name","LatestDataDate(YEAR)","LatestDataDate(MONTH)","LatestDataDate(DAY)","LatestDataDate(HOUR)","LatestDataDate(MIN)","LatestDataDate(SEC)","水位","水量","酸性度","水温","粘度","センサーデータ"
"2022/08/01 14:00","2022","8","1","5","0","0","6.79","217","81","43.32","12262","","----","----","----","----","----","----","----","----","----","----","----","----","----","----","----","----","----","----","----","----"
"2022/08/01 14:01","##","##","##","##","##","##","6.79","214","81","43.35","12487","
","----","----","----","----","----","----","----","----","----","----","----","----","----","----","----","----","----","----","----","----"
"2022/08/01 14:02","2022","8","1","5","2","0","6.79","214","81","43.32","12337","","----","----","----","----","----","----","----","----","----","----","----","----","----","----","----","----","----","----","----","----"
"2022/08/01 14:03","2022","8","1","5","3","0","6.79","218","80","43.35","12412","
","----","----","----","----","----","----","----","----","----","----","----","----","----","----","----","----","----","----","----","----"

コメントを投稿

0 コメント