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, 2020 in Python by anonymous
• 120 points
782 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, 2020 by Gitika
• 65,910 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 28, 2018 in Python by Nabarupa Das
2,415 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
13,238 views
0 votes
0 answers
+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
5,238 views
0 votes
2 answers
+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 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,023 views
0 votes
1 answer
0 votes
3 answers

(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
• 52,360 points
98,493 views
0 votes
1 answer

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

This error occurs because you are using ...READ MORE

answered Sep 9, 2020 in Python by Gitika
• 65,910 points
13,624 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP