In [ ]:
import numpy as np
import pandas as pd
import pprint
import math
from IPython.display import display, HTML

In [ ]:
s1 = pd.Series({'a': 12, 'b': 21, 's':1,'p':1000,'x':None})
print(s1)
print(s1.index)
print(s1[1:3])
print(s1[2:-1])

In [ ]:
df0 = pd.DataFrame(s1)
df0

In [36]:
dfA = pd.DataFrame({'A': range(3), 'B': 'text', 'C': [1,2,4]}, index=['one', 'two', 'three'])
display(dfA)
dfA[dfA['C'] == 2]
print(dfA.index.str.split('o'))
# help(dfA.index.str)
display(dfA['C'].idxmax())
(dfA['A'] - dfA['C']).idxmax()


A B C
one 0 text 1
two 1 text 2
three 2 text 4
Index([['', 'ne'], ['tw', ''], ['three']], dtype='object')
'three'
Out[36]:
'one'

In [8]:
df1 = pd.DataFrame(np.random.randn(5,3), columns=['weight', 'size', 'entropy'])
s2 = pd.Series([1,1,2], index=['weight', 'entropy','size'])
print(df1, s2, sep='\n\n')
print()
print(df1*s2)


     weight      size   entropy
0  0.654187  0.727784  0.496123
1  1.134990 -0.162077 -1.079547
2  0.208266 -1.157130 -0.612578
3 -0.893273 -1.349030 -0.885265
4  0.468698  0.016658 -0.799512

weight     1
entropy    1
size       2
dtype: int64

    entropy      size    weight
0  0.496123  1.455568  0.654187
1 -1.079547 -0.324153  1.134990
2 -0.612578 -2.314260  0.208266
3 -0.885265 -2.698059 -0.893273
4 -0.799512  0.033316  0.468698

In [9]:
print(df1.index.str)
print(df1.columns)
print(df1.values)
print(type(df1.values))


---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-9-cdc1553cf003> in <module>
----> 1 print(df1.index.str)
      2 print(df1.columns)
      3 print(df1.values)
      4 print(type(df1.values))

c:\users\samuel\appdata\local\programs\python\python36\lib\site-packages\pandas\core\accessor.py in __get__(self, obj, cls)
    131             # we're accessing the attribute of the class, i.e., Dataset.geo
    132             return self._accessor
--> 133         accessor_obj = self._accessor(obj)
    134         # Replace the property with the accessor object. Inspired by:
    135         # http://www.pydanny.com/cached-property.html

c:\users\samuel\appdata\local\programs\python\python36\lib\site-packages\pandas\core\strings.py in __init__(self, data)
   1893 
   1894     def __init__(self, data):
-> 1895         self._validate(data)
   1896         self._is_categorical = is_categorical_dtype(data)
   1897 

c:\users\samuel\appdata\local\programs\python\python36\lib\site-packages\pandas\core\strings.py in _validate(data)
   1931                            "(i.e. inferred_type is 'string', 'unicode' or "
   1932                            "'mixed')")
-> 1933                 raise AttributeError(message)
   1934             if data.nlevels > 1:
   1935                 message = ("Can only use .str accessor with Index, not "

AttributeError: Can only use .str accessor with string values (i.e. inferred_type is 'string', 'unicode' or 'mixed')