How do I refer to the index of my Pandas dataframe?

I have a Pandas dataframe where I have designated some of the columns as indices: planets_dataframe.set_index([‘host’,’name’], inplace=True) and would like to be able to refer to these indices in a variety of contexts. Using the name of an index works fine in queries planets_dataframe.query(‘host == “PSR 1257 12″‘) but results in an error if try … Read more

Plotting datetimeindex on x-axis with matplotlib creates wrong ticks in pandas 0.15 in contrast to 0.14

I create a simple pandas dataframe with some random values and a DatetimeIndex like so: import pandas as pd from numpy.random import randint import datetime as dt import matplotlib.pyplot as plt # create a random dataframe with datetimeindex dateRange = pd.date_range(‘1/1/2011’, ‘3/30/2011′, freq=’D’) randomInts = randint(1, 50, len(dateRange)) df = pd.DataFrame({‘RandomValues’ : randomInts}, index=dateRange) Then … Read more

Expressions with “== True” and “is True” give different results

I have the following MCVE: #!/usr/bin/env python3 import pandas as pd df = pd.DataFrame([True, False, True]) print(“Whole DataFrame:”) print(df) print(“\nFiltered DataFrame:”) print(df[df[0] == True]) The output is the following, which I expected: Whole DataFrame: 0 0 True 1 False 2 True Filtered DataFrame: 0 0 True 2 True Okay, but the PEP8 style seems to … Read more

pandas.read_html not support decimal comma

I was reading an xlm file using pandas.read_html and works almost perfect, the problem is that the file has commas as decimal separators instead of dots (the default in read_html). I could easily replace the commas by dots in one file, but i have almost 200 files with that configuration. with pandas.read_csv you can define … Read more

pandas.concat of multiple data frames using only common columns

I have multiple pandas data frame objects cost1, cost2, cost3 …. They have different column names (and number of columns) but have some in common. Number of columns is fairly large in each data frame, hence handpicking the common columns manually will be painful. How can I append rows from all of these data frames … Read more