0
votes

this is driving me nuts, I can't plot column 'b' it plots only column 'A'.....

this is my code, no idea what I'm doing wrong, probably something silly... the dataframe seems ok, weirdness also is that I can access both df['A'] and df['b'] but only df['A'].plot() works, if I issue a df['b'].plot() I get this error :

Traceback (most recent call last): File "C:\Python27\lib\site-packages\IPython\core\interactiveshell.py", line 2883, in run_code exec(code_obj, self.user_global_ns, self.user_ns) File "", line 1, in df['b'].plot() File "C:\Python27\lib\site-packages\pandas\tools\plotting.py", line 2511, in plot_series **kwds) File "C:\Python27\lib\site-packages\pandas\tools\plotting.py", line 2317, in _plot plot_obj.generate() File "C:\Python27\lib\site-packages\pandas\tools\plotting.py", line 921, in generate self._compute_plot_data() File "C:\Python27\lib\site-packages\pandas\tools\plotting.py", line 997, in _compute_plot_data 'plot'.format(numeric_data.class.name)) TypeError: Empty 'Series': no numeric data to plot

import sqlalchemy
import pandas as pd
import matplotlib.pyplot as plt

engine = sqlalchemy.create_engine(
    'sqlite:///C:/Users/toto/PycharmProjects/my_db.sqlite')

tables = engine.table_names()
dic = {}
for t in tables:
    sql = 'SELECT t."weight" FROM "' + t + '" t WHERE t."udl"="IBE SM"'
    dic[t] = (pd.read_sql(sql, engine)['weight'][0], pd.read_sql(sql, engine)['weight'][1])

df = pd.DataFrame.from_dict(dic, orient='index').sort_index()
df = df.set_index(pd.DatetimeIndex(df.index))
df.columns = ['A', 'b']
print(df)

print(df.info())

df.plot()
plt.show()

this is the 2 print

               A     b
2014-08-05  1.81  3.39
2014-08-06  1.81  3.39
2014-08-07  1.81  3.39
2014-08-08  1.80  3.37
2014-08-11  1.79  3.35
2014-08-13  1.80  3.36
2014-08-14  1.80  3.35
2014-08-18  1.80  3.35
2014-08-19  1.79  3.34
2014-08-20  1.80  3.35
2014-08-27  1.79  3.35
2014-08-28  1.80  3.35
2014-08-29  1.79  3.35
2014-09-01  1.79  3.35
2014-09-02  1.79  3.35
2014-09-03  1.79  3.36
2014-09-04  1.79  3.37
2014-09-05  1.80  3.38
2014-09-08  1.79  3.36
2014-09-09  1.79  3.35
2014-09-10  1.78  3.35
2014-09-11  1.78  3.34
2014-09-12  1.78  3.34
2014-09-15  1.78  3.35
2014-09-16  1.78  3.35
2014-09-17  1.78  3.35
2014-09-18  1.78  3.34
2014-09-19  1.79  3.35
2014-09-22  1.79  3.36
2014-09-23  1.80  3.37
...          ...   ...
2014-12-10  1.73  3.29
2014-12-11  1.74  3.27
2014-12-12  1.74  3.25
2014-12-15  1.74  3.24
2014-12-16  1.74  3.27
2014-12-17  1.75  3.28
2014-12-18  1.76  3.29
2014-12-19  1.04  1.39
2014-12-22  1.04  1.39
2014-12-23  1.04   1.4
2014-12-24  1.04  1.39
2014-12-29  1.04  1.39
2014-12-30  1.04   1.4
2015-01-02  1.04   1.4
2015-01-05  1.04   1.4
2015-01-06  1.04   1.4
2015-01-07   NaN  1.39
2015-01-08   NaN  1.39
2015-01-09   NaN  1.39
2015-01-12   NaN  1.38
2015-01-13   NaN  1.38
2015-01-14   NaN  1.38
2015-01-15   NaN  1.38
2015-01-16   NaN  1.38
2015-01-19   NaN  1.39
2015-01-20   NaN  1.38
2015-01-21   NaN  1.39
2015-01-22   NaN   1.4
2015-01-23   NaN   1,4
2015-01-26   NaN  1.41

[107 rows x 2 columns]
<class 'pandas.core.frame.DataFrame'>
DatetimeIndex: 107 entries, 2014-08-05 00:00:00 to 2015-01-26 00:00:00
Data columns (total 2 columns):
A    93 non-null float64
b    107 non-null object
dtypes: float64(1), object(1)
memory usage: 2.1+ KB
None

Process finished with exit code 0
1
just got it, b is object and non-float because of 2015-01-23 NaN 1,4 - euri10
Post your answer and accept it so this post is marked as answered - EdChum
can accept it in 2 days :) - euri10

1 Answers

0
votes

just got it, 'b' is of object type and not float64 because of this line : 2015-01-23 NaN 1,4