Fix Python – How does assignment work with list slices?

Python docs says that slicing a list returns a new list.
Now if a “new” list is being returned I’ve the following questions related to “Assignment to slices”
a = [1, 2, 3]
a[0:2] = [4, 5]
print a

Now the output would be:
[4, 5, 3]

How can something that is returning something come on the left side of expression?
Yes, I read the docs and it say….

Fix Python – Pandas selecting by label sometimes return Series, sometimes returns DataFrame

In Pandas, when I select a label that only has one entry in the index I get back a Series, but when I select an entry that has more then one entry I get back a data frame.
Why is that? Is there a way to ensure I always get back a data frame?
In [1]: import pandas as pd

In [2]: df = pd.DataFrame(data=range(5), index=[1, 2, 3, 3, 3])

In [3]: type….

Fix Python – Extract elements of list at odd positions

So I want to create a list which is a sublist of some existing list.
For example,
L = [1, 2, 3, 4, 5, 6, 7], I want to create a sublist li such that li contains all the elements in L at odd positions.
While I can do it by
L = [1, 2, 3, 4, 5, 6, 7]
li = []
count = 0
for i in L:
if count % 2 == 1:
count += 1

But I want ….

Fix Python – Implementing slicing in __getitem__

I am trying to implement slice functionality for a class I am making that creates a vector representation.
I have this code so far, which I believe will properly implement the slice but whenever I do a call like v[4] where v is a vector python returns an error about not having enough parameters. So I am trying to figure out how to define the getit….

Fix Python – Select rows in pandas MultiIndex DataFrame

What are the most common pandas ways to select/filter rows of a dataframe whose index is a MultiIndex?

Slicing based on a single value/label
Slicing based on multiple labels from one or more levels
Filtering on boolean conditions and expressions
Which methods are applicable in what circumstances

Assumptions for simplicity:

input dataframe does ….

Fix Python – How to take column-slices of dataframe in pandas

I load some machine learning data from a CSV file. The first 2 columns are observations and the remaining columns are features.
Currently, I do the following:
data = pandas.read_csv(‘mydata.csv’)

which gives something like:
data = pandas.DataFrame(np.random.rand(10,5), columns = list(‘abcde’))

I’d like to slice this dataframe in two dataframes: ….