I'm trying to set data in an existing chart using python-pptx.
from pptx import Presentation
pres_path = "C:\\pres.pptx"
pres = Presentation(pres_path)
pres.slides[3].shapes[4].chart.series[0].values
(92.0, 330.0, 309.0, 313.0, 356.0, 421.0, 457.0)
pres.slides[3].shapes[4].chart.series[0].values = (1,2,3)
Traceback (most recent call last):
File "<input>", line 1, in <module>
AttributeError: can't set attribute
There's a method mentioned in the documentation which seems relevant, but I can't understand how to use it:
http://python-pptx.readthedocs.org/en/latest/_modules/pptx/chart/data.html
pres.slides[3].shapes[4].chart.replace_data((1,2,3))
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "C:\Python27\lib\site-packages\pptx\chart\chart.py", line 119, in replace_data
_SeriesRewriter.replace_series_data(self._chartSpace, chart_data)
File "C:\Python27\lib\site-packages\pptx\chart\chart.py", line 197, in replace_series_data
sers = cls._adjust_ser_count(chartSpace, len(chart_data.series))
AttributeError: 'tuple' object has no attribute 'series'
I'd appreciate any help you can provide.
Thanks!
To add a new series to an existing table behind a chart you need to do 3 things:
create an instance of ChartData()
provide category name
add the new series to the ChartData() object, using the "add_series()" func.
chart_data = ChartData()
chart_data.categories = 'category_name'
for col_idx, col in enumerate(single_df.columns):
chart_data.add_series(col, (single_df.ix[:, col_idx].values))
shp.chart.replace_data(chart_data)
Related
I have defined a new derived dimension with
[molar_energy] = [energy] / [substance]
However, if I do the following it complains:
>>> UR.get_compatible_units('[molar_energy]')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/cedric/.local/share/virtualenvs/MatDB--uGOYMXa/lib/python3.9/site-packages/pint/registry.py", line 881, in get_compatible_units
equiv = self._get_compatible_units(input_units, group_or_system)
File "/Users/cedric/.local/share/virtualenvs/MatDB--uGOYMXa/lib/python3.9/site-packages/pint/registry.py", line 2082, in _get_compatible_units
ret = super()._get_compatible_units(input_units, group_or_system)
File "/Users/cedric/.local/share/virtualenvs/MatDB--uGOYMXa/lib/python3.9/site-packages/pint/registry.py", line 1835, in _get_compatible_units
ret = super()._get_compatible_units(input_units, group_or_system)
File "/Users/cedric/.local/share/virtualenvs/MatDB--uGOYMXa/lib/python3.9/site-packages/pint/registry.py", line 891, in _get_compatible_units
return self._cache.dimensional_equivalents[src_dim]
KeyError: <UnitsContainer({'[length]': 2, '[mass]': 1, '[substance]': -1, '[time]': -2})
I saw that there is a conversion included in a context but I don't use it. What I am doing wrong?
Thanks for your help
PS: logged issue https://github.com/hgrecco/pint/issues/1418
Just leaving the solution here for anyone who faces this issue as well.
I just added a made-up unit and it worked
# Molar Energy
[molar_energy] = [energy] / [substance]
mol_en = J / mol
I am trying to fetch value from cell using below code:
import openpyxl
wb=openpyxl.load_workbook(r'C:\Users\xyz\Desktop\xxx.xlsx')
sheet=wb.active
v = sheet.cell(9,9).value
print(v)
When I execute the code, I get the following error:
Warning (from warnings module):
File "C:\Users\XYZ\AppData\Local\Programs\Python\Python36-32\lib\site-packages\openpyxl\worksheet\worksheet.py", line 303
warn("Using a coordinate with ws.cell is deprecated. Use ws[coordinate] instead")
UserWarning: Using a coordinate with ws.cell is deprecated. Use ws[coordinate] instead
Traceback (most recent call last):
File "C:/Users/XYZ/Desktop/test.py", line 14, in <module>
v = sheet.cell(9,9).value
File "C:\Users\XYZ\AppData\Local\Programs\Python\Python36-32\lib\site-packages\openpyxl\worksheet\worksheet.py", line 304, in cell
row, column = coordinate_to_tuple(coordinate)
File "C:\Users\XYZ\AppData\Local\Programs\Python\Python36-32\lib\site-packages\openpyxl\utils\cell.py", line 185, in coordinate_to_tuple
col, row = coordinate_from_string(coordinate)
File "C:\Users\XYZ\AppData\Local\Programs\Python\Python36-32\lib\site-packages\openpyxl\utils\cell.py", line 45, in coordinate_from_string
match = COORD_RE.match(coord_string.upper())
AttributeError: 'int' object has no attribute 'upper'
Can anyone say what is wrong with my program.
You need to use keyword arguments:
v = sheet.cell(row=9, column=9).value
I am trying to train some data for a classification tool I am building. I have done some simple examples and it works fine.
I am now trying to use some data from work (which is what it will be used on), and I am getting a TypeError: 'float' object is not iterable error, the traceback is here:
Traceback (most recent call last):
File "C:/Users/nicholas/Desktop/machineTraining/classLearning.py", line 13, in <module>
cl = NaiveBayesClassifier(train)
File "C:\Users\nicholas\AppData\Local\Programs\Python\Python36-32\lib\site-packages\textblob\classifiers.py", line 205, in __init__
super(NLTKClassifier, self).__init__(train_set, feature_extractor, format, **kwargs)
File "C:\Users\nicholas\AppData\Local\Programs\Python\Python36-32\lib\site-packages\textblob\classifiers.py", line 139, in __init__
self._word_set = _get_words_from_dataset(self.train_set) #Keep a hidden set of unique words.
File "C:\Users\nicholas\AppData\Local\Programs\Python\Python36-32\lib\site-packages\textblob\classifiers.py", line 63, in _get_words_from_dataset
return set(all_words)
This is my code:
df = pd.read_csv("C:/Users/nicholas\Desktop/trainData.csv", encoding='latin-1')
df['train'] = df[['Summary', 'Primary Classification']].apply(tuple, axis=1)
aTrain = df['train'].values.tolist()
train = aTrain
cl = NaiveBayesClassifier(train)
Any ideas on what is going wrong?
When trying to set up the DataIterator as explained on neon tutorial.
from neon.data import DataIterator
import numpy as np
X = np.random.rand(10000, 3072)
y = np.random.randint(1, 11, 10000)
train = DataIterator(X=X, y=y, nclass=10, lshape=(3, 32, 32))
I encountered a weird error:
ERROR:neon.data.dataiterator:DataIterator class has been deprecated and renamed"ArrayIterator" please use that name.
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "neon/data/dataiterator.py", line 168, in __init__
super(DataIterator, self).__init__(*args, **kwargs)
File "neon/data/dataiterator.py", line 82, in __init__
self.Xdev = [self.be.array(x) for x in X]
AttributeError: 'NoneType' object has no attribute 'array'
I then tried with ArrayIterator, keeping X, y the same.
ArrayIterator(X=X, y=y, nclass=10, lshape=(3,32,32))
With the same NoneType error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "neon/data/dataiterator.py", line 82, in __init__
self.Xdev = [self.be.array(x) for x in X]
AttributeError: 'NoneType' object has no attribute 'array'
Why would this be the case? Is there an easy fix?
Fixed the problem by generating backend.
from neon.backends import gen_backend
be = gen_backend()
(...)
I have a document:
class Hamburger(Document):
size = IntField(default=0, required=True)
which I can use fine
h = Hamburger()
h.size = 5
h.save()
until I try an update_one for example
Hamburger.objects().update_one(set__size=5)
which throws this exception:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/site-packages/mongoengine/queryset/base.py", line 467, in update_one
upsert=upsert, multi=False, write_concern=write_concern, **update)
File "/usr/local/lib/python2.7/site-packages/mongoengine/queryset/base.py", line 430, in update
update = transform.update(queryset._document, **update)
File "/usr/local/lib/python2.7/site-packages/mongoengine/queryset/transform.py", line 207, in update
field = cleaned_fields[-1]
IndexError: list index out of range
It is possible to have a Document with a field called size? Is there any way to achieve this?