import pandas as pd
pd.__version__
'0.11.0'
dr = pd.date_range('now',periods=10)
df = pd.DataFrame(randn(10,2),index=dr)
df
0 | 1 | |
---|---|---|
2013-05-17 00:42:32 | -0.389840 | -0.152778 |
2013-05-18 00:42:32 | 0.821756 | 0.208864 |
2013-05-19 00:42:32 | 0.486829 | -0.034712 |
2013-05-20 00:42:32 | 2.252697 | 0.689548 |
2013-05-21 00:42:32 | -0.022469 | 0.228613 |
2013-05-22 00:42:32 | -0.133534 | 0.663756 |
2013-05-23 00:42:32 | -1.021987 | -0.339355 |
2013-05-24 00:42:32 | 0.533003 | 0.246249 |
2013-05-25 00:42:32 | 2.572123 | 1.843940 |
2013-05-26 00:42:32 | 0.296904 | 0.019658 |
df[1][:5]=nan
df
0 | 1 | |
---|---|---|
2013-05-17 00:42:32 | -0.389840 | NaN |
2013-05-18 00:42:32 | 0.821756 | NaN |
2013-05-19 00:42:32 | 0.486829 | NaN |
2013-05-20 00:42:32 | 2.252697 | NaN |
2013-05-21 00:42:32 | -0.022469 | NaN |
2013-05-22 00:42:32 | -0.133534 | 0.663756 |
2013-05-23 00:42:32 | -1.021987 | -0.339355 |
2013-05-24 00:42:32 | 0.533003 | 0.246249 |
2013-05-25 00:42:32 | 2.572123 | 1.843940 |
2013-05-26 00:42:32 | 0.296904 | 0.019658 |
This way it works:
df[0].plot()
<matplotlib.axes.AxesSubplot at 0x117ff9e10>
display(gcf())
df[1].plot()
<matplotlib.axes.AxesSubplot at 0x117ff9e10>
display(gcf())
df['selector'] = df[1].notnull()
df
0 | 1 | selector | |
---|---|---|---|
2013-05-17 00:42:32 | -0.389840 | NaN | False |
2013-05-18 00:42:32 | 0.821756 | NaN | False |
2013-05-19 00:42:32 | 0.486829 | NaN | False |
2013-05-20 00:42:32 | 2.252697 | NaN | False |
2013-05-21 00:42:32 | -0.022469 | NaN | False |
2013-05-22 00:42:32 | -0.133534 | 0.663756 | True |
2013-05-23 00:42:32 | -1.021987 | -0.339355 | True |
2013-05-24 00:42:32 | 0.533003 | 0.246249 | True |
2013-05-25 00:42:32 | 2.572123 | 1.843940 | True |
2013-05-26 00:42:32 | 0.296904 | 0.019658 | True |
df[0].plot()
<matplotlib.axes.AxesSubplot at 0x118023090>
display(gcf())
This way the x-axis is being rescaled. How can I fix it at the previous setting?
df[df.selector][0].plot(style='r*')
<matplotlib.axes.AxesSubplot at 0x118023090>
display(gcf())