Python Basic

  • Python

  • PY

[40]:
from pandas import Series

Series(['4', '3', '2', '1'])
[40]:
0    4
1    3
2    2
3    1
dtype: object
[43]:
from pandas import DataFrame

df = DataFrame(data=[[1, 2, 3], [4, 5, 6]], columns=['a', 'b', 'c'], index=['X', 'Y'])
df[['a', 'b']]
[43]:
a b
X 1 2
Y 4 5
[45]:
# list comprehension

[i**2 for i in range(10)]
[45]:
[0, 1, 4, 9, 16, 25, 36, 49, 64, 81]
[47]:
string = 'aaa' if 0>1 else 'bbb'
string
[47]:
'bbb'
[49]:
['Bought']*5
[49]:
['Bought', 'Bought', 'Bought', 'Bought', 'Bought']