In [2]:
from sympy import isprime
L = [i for i in range(100) if isprime(i)]
L
Out[2]:
In [3]:
from pandas import Series
s = Series(L)
s
Out[3]:
In [4]:
s[13]
Out[4]:
In [7]:
s.argmax()
Out[7]:
In [8]:
s.cumsum()
Out[8]:
In [9]:
s.describe()
Out[9]:
In [10]:
s.mean()
Out[10]:
In [11]:
s.std()
Out[11]:
In [12]:
s.min()
Out[12]:
In [13]:
def f(p):
return p**2 - 3
s.apply(f)
Out[13]:
In [16]:
s * 10000 + 45
Out[16]:
In [17]:
s / sum(s)
Out[17]:
In [18]:
t = Series([i**3 for i in range(25)])
In [19]:
t
Out[19]:
In [22]:
s ** t
Out[22]:
In [25]:
from pandas import concat
df = concat([s,t], axis=1)
df
Out[25]:
In [26]:
type(df)
Out[26]:
In [34]:
import pandas as pa
d = {'nb premiers':s, 'cubes':t}
df = pa.DataFrame(d, columns=['nb premiers', 'cubes'])
In [35]:
df
Out[35]:
In [37]:
df.describe()
Out[37]:
In [36]:
df['cubes']
Out[36]:
In [38]:
L = [isprime(i) for i in range(10000)]
In [39]:
L[:10]
Out[39]:
In [40]:
L = map(isprime, range(10000))
In [43]:
L[:10]
Out[43]:
In [44]:
s = Series(L)
In [45]:
t = s.cumsum()
In [49]:
df = pa.DataFrame()
In [50]:
df['isprime'] = s
In [51]:
df['pi_x'] = t
In [53]:
df.head()
Out[53]:
In [55]:
df.tail(8)
Out[55]:
In [56]:
df[500:520]
Out[56]:
In [57]:
from math import log
In [58]:
10000 / log(10000)
Out[58]:
In [62]:
from math import sqrt
12.29*sqrt(10000)
Out[62]:
In [63]:
def x_sur_log_x(x):
if x > 1:
return x/log(x)
else:
return None
In [64]:
X = Series(range(10000))
gauss = X.apply(x_sur_log_x)
nous = X.apply(lambda x:12.29*sqrt(x))
In [65]:
df['x_logx'] = gauss
df['nous'] = nous
In [66]:
df.head()
Out[66]:
In [67]:
%matplotlib inline
In [68]:
df.plot()
Out[68]:
In [70]:
del df['nous']
df[:100].plot()
Out[70]:
In [79]:
from sympy import Li
df['Li_x'] = Series([Li(x).n() for x in range(10000)], dtype='float64')
In [80]:
df.head()
Out[80]:
In [81]:
df.Li_x
Out[81]:
In [84]:
df.plot()
Out[84]:
In [85]:
from pandas import ExcelWriter
writer = ExcelWriter('tableau.xlsx')
df.to_excel(writer, 'Feuille 1')
writer.save()
In [87]:
df.to_csv('tableau.csv')
In [88]:
ls
In [89]:
!head tableau.csv
In [91]:
df2 = pa.read_excel('tableau.xlsx')
In [92]:
df2.head()
Out[92]:
In [ ]:
pa.read_csv
In [ ]: