実行内容
import matplotlib.pyplot as plt
import seaborn as sns
import pandas as pd
csv読み込み
df=pd.read_csv("円.csv",sep=",")
df.columns=['x','y(上円)','y(下円)']
csvの中身
x,y(上円),y(下円),,,
,-4.0,0,0,,,
,-3.5,1.93649167310371,-1.93649167310371,,,
,-3.0,2.64575131106459,-2.64575131106459,,,
,-2.5,3.1224989991992,-3.1224989991992,,,
,-2.0,3.46410161513775,-3.46410161513775,,,
,-1.5,3.70809924354783,-3.70809924354783,,,
,-1.0,3.87298334620742,-3.87298334620742,,,
,-0.5,3.96862696659689,-3.96862696659689,,,
,0.0,4,-4,,,
,0.5,3.96862696659689,-3.96862696659689,,,
,1.0,3.87298334620742,-3.87298334620742,,,
,1.5,3.70809924354783,-3.70809924354783,,,
,2.0,3.46410161513775,-3.46410161513775,,,
,2.5,3.1224989991992,-3.1224989991992,,,
,3.0,2.64575131106459,-2.64575131106459,,,
,3.5,1.93649167310371,-1.93649167310371,,,
,4.0,0,0,,,
エラー内容
ValueError Traceback (most recent call last)
/var/folders/1b/4r83ph916kb86bjsvm74d7740000gn/T/ipykernel_1191/668428342.py in <module>
1 #csv読み込み
2 df=pd.read_csv("円.csv",sep=",")
----> 3 df.columns=['x','y(上円)','y(下円)']
/usr/local/lib/python3.9/site-packages/pandas/core/generic.py in setattr(self, name, value)
5498 try:
5499 object.getattribute(self, name)
-> 5500 return object.setattr(self, name, value)
5501 except AttributeError:
5502 pass
/usr/local/lib/python3.9/site-packages/pandas/_libs/properties.pyx in pandas._libs.properties.AxisProperty.set()
/usr/local/lib/python3.9/site-packages/pandas/core/generic.py in _set_axis(self, axis, labels)
764 def _set_axis(self, axis: int, labels: Index) -> None:
765 labels = ensure_index(labels)
--> 766 self._mgr.set_axis(axis, labels)
767 self._clear_item_cache()
768
/usr/local/lib/python3.9/site-packages/pandas/core/internals/managers.py in set_axis(self, axis, new_labels)
214 def set_axis(self, axis: int, new_labels: Index) -> None:
215 # Caller is responsible for ensuring we have an Index object.
--> 216 self._validate_set_axis(axis, new_labels)
217 self.axes[axis] = new_labels
218
/usr/local/lib/python3.9/site-packages/pandas/core/internals/base.py in _validate_set_axis(self, axis, new_labels)
55
56 elif new_len != old_len:
---> 57 raise ValueError(
58 f"Length mismatch: Expected axis has {old_len} elements, new "
59 f"values have {new_len} elements"
ValueError: Length mismatch: Expected axis has 6 elements, new values have 3 elements
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。