position error

0 votes

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

df = pd.read_csv('Rund1.csv', header = None)
display(df)
df.plot(yerr='Intensity(%)',xerr='Position (m)')


plt.title('Run1: graph of position vs light intensity')
plt.xlabel('Position (m)')
plt.ylabel('Intensity (%)')
print(df.min())
print(df.max())

KeyError                                  Traceback (most recent call last)
~\Anaconda3\lib\site-packages\pandas\core\indexes\base.py in get_loc(self, key, method, tolerance)
   2656             try:
-> 2657                 return self._engine.get_loc(key)
   2658             except KeyError:

pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()

pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()

pandas/_libs/index_class_helper.pxi in pandas._libs.index.Int64Engine._check_type()

KeyError: 'Position (m)'

During handling of the above exception, another exception occurred:

KeyError                                  Traceback (most recent call last)
<ipython-input-79-c064300052af> in <module>
      5 df = pd.read_csv('Rund1.csv', header = None)
      6 display(df)
----> 7 df.plot(yerr='Intensity(%)',xerr='Position (m)')
      8 
      9 

~\Anaconda3\lib\site-packages\pandas\plotting\_core.py in __call__(self, x, y, kind, ax, subplots, sharex, sharey, layout, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, secondary_y, sort_columns, **kwds)
   2940                           fontsize=fontsize, colormap=colormap, table=table,
   2941                           yerr=yerr, xerr=xerr, secondary_y=secondary_y,
-> 2942                           sort_columns=sort_columns, **kwds)
   2943     __call__.__doc__ = plot_frame.__doc__
   2944 

~\Anaconda3\lib\site-packages\pandas\plotting\_core.py in plot_frame(data, x, y, kind, ax, subplots, sharex, sharey, layout, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, secondary_y, sort_columns, **kwds)
   1971                  yerr=yerr, xerr=xerr,
   1972                  secondary_y=secondary_y, sort_columns=sort_columns,
-> 1973                  **kwds)
   1974 
   1975 

~\Anaconda3\lib\site-packages\pandas\plotting\_core.py in _plot(data, x, y, subplots, ax, kind, **kwds)
   1797                     data.columns = label_name
   1798 
-> 1799         plot_obj = klass(data, subplots=subplots, ax=ax, kind=kind, **kwds)
   1800 
   1801     plot_obj.generate()

~\Anaconda3\lib\site-packages\pandas\plotting\_core.py in __init__(self, data, **kwargs)
    948 
    949     def __init__(self, data, **kwargs):
--> 950         MPLPlot.__init__(self, data, **kwargs)
    951         if self.stacked:
    952             self.data = self.data.fillna(value=0)

~\Anaconda3\lib\site-packages\pandas\plotting\_core.py in __init__(self, data, kind, by, subplots, sharex, sharey, use_index, figsize, grid, legend, rot, ax, fig, title, xlim, ylim, xticks, yticks, sort_columns, fontsize, secondary_y, colormap, table, layout, **kwds)
    159         yerr = kwds.pop('yerr', None)
    160         self.errors = {kw: self._parse_errorbars(kw, err)
--> 161                        for kw, err in zip(['xerr', 'yerr'], [xerr, yerr])}
    162 
    163         if not isinstance(secondary_y, (bool, tuple, list,

~\Anaconda3\lib\site-packages\pandas\plotting\_core.py in <dictcomp>(.0)
    159         yerr = kwds.pop('yerr', None)
    160         self.errors = {kw: self._parse_errorbars(kw, err)
--> 161                        for kw, err in zip(['xerr', 'yerr'], [xerr, yerr])}
    162 
    163         if not isinstance(secondary_y, (bool, tuple, list,

~\Anaconda3\lib\site-packages\pandas\plotting\_core.py in _parse_errorbars(self, label, err)
    713         # errors are a column in the dataframe
    714         elif isinstance(err, string_types):
--> 715             evalues = self.data[err].values
    716             self.data = self.data[self.data.columns.drop(err)]
    717             err = np.atleast_2d(evalues)

~\Anaconda3\lib\site-packages\pandas\core\frame.py in __getitem__(self, key)
   2925             if self.columns.nlevels > 1:
   2926                 return self._getitem_multilevel(key)
-> 2927             indexer = self.columns.get_loc(key)
   2928             if is_integer(indexer):
   2929                 indexer = [indexer]

~\Anaconda3\lib\site-packages\pandas\core\indexes\base.py in get_loc(self, key, method, tolerance)
   2657                 return self._engine.get_loc(key)
   2658             except KeyError:
-> 2659                 return self._engine.get_loc(self._maybe_cast_indexer(key))
   2660         indexer = self.get_indexer([key], method=method, tolerance=tolerance)
   2661         if indexer.ndim > 1 or indexer.size > 1:

pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()

pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()

pandas/_libs/index_class_helper.pxi in pandas._libs.index.Int64Engine._check_type()

KeyError: 'Position (m)'
Oct 23 in Python by anonymous
• 120 points
42 views
Hi,

Can you share your Dataset? It is related to your field. You have mentioned the wrong field in your plot function.

1 answer to this question.

0 votes
Hi, @There,

The key error generally means the key doesn't exist. So, are you sure 'path' exist.?
answered Oct 23 by Gitika
• 48,320 points

Related Questions In Python

0 votes
2 answers

Error: Speech to Text Codec cannot decode the bytes in position

import speech_recognition as sr r = sr.Recognizer() audio ='C\Users\Desktop\audiofile1.wav' with ...READ MORE

answered Nov 27, 2018 in Python by Nabarupa Das
865 views
0 votes
2 answers

Python Error "UnicodeEncodeError: 'ascii' codec can't encode character u'\u03b1' in position 20: ordinal not in range(128)"

import csv import sys reload(sys) sys.setdefaultencoding('utf8') data = [["a", "b", u'\xe9']] with ...READ MORE

answered Jun 28, 2019 in Python by anonymous
5,499 views
+1 vote
1 answer

(unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape

You are getting this error because you ...READ MORE

answered Dec 31, 2019 in Python by Kalgi
• 51,970 points
15,829 views
+2 votes
2 answers

Error while printing hello world in python.

You must be trying this command in ...READ MORE

answered Mar 31, 2018 in Python by GandalfDwhite
• 1,320 points
798 views
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 1,557 views
0 votes
0 answers
0 votes
1 answer
+1 vote
8 answers

How to fix this? ValueError: invalid literal for int() with base 10 error in Python

Just for the record: >>> int('55063.000000') Traceback (most recent ...READ MORE

answered Aug 17 in Python by pakainfo
• 200 points
180,607 views