I was working before on Raspberry Pi, but once I moved to an Ubuntu PC, the code below is not working anymore. I guess I need to somehow install that csvformat, but not sure how.
Python code:
import os
import subprocess
import pandas
import pandas as pd
subprocess.call("csvformat -t plates.txt >> plates.csv", shell=True)
f=pd.read_csv("plates.csv")
keep_col = [11,13]
new_f = f[keep_col]
new_f.to_csv("new_plates.csv", index=False)
subprocess.call("sudo rm plates.csv", shell=True)
df = pd.read_csv("new_plates.csv", names=["Plates", "Name"])
df["Plates"] = df["Plates"].str.split().apply("".join)
print(df)
Error message:
/bin/sh: 1: csvformat: not found
Traceback (most recent call last):
File "script.py", line 14, in <module>
new_f = f[keep_col]
File "/usr/local/lib/python3.6/dist-packages/pandas/core/frame.py", line 2934, in __getitem__
raise_missing=True)
File "/usr/local/lib/python3.6/dist-packages/pandas/core/indexing.py", line 1354, in _convert_to_indexer
return self._get_listlike_indexer(obj, axis, **kwargs)[1]
File "/usr/local/lib/python3.6/dist-packages/pandas/core/indexing.py", line 1161, in _get_listlike_indexer
raise_missing=raise_missing)
File "/usr/local/lib/python3.6/dist-packages/pandas/core/indexing.py", line 1246, in _validate_read_indexer
key=key, axis=self.obj._get_axis_name(axis)))
KeyError: "None of [Int64Index([11, 13], dtype='int64')] are in the [columns]