Using .sub() over a variable length dataframe?

I have a need to calculate the difference between one static column in a dataframe and some variable amount of columns that make up the rest of the dataframe. My data look like this: School District | 01-01-2017 | 01-02-2017 |...| 02-01-2017 | Base...
more »

2017-06-21 21:06 (2) Answers

Ignoring NaN in a dataframe

I want to find the unique elements in a column of a dataframe which have missing values. i tried this: df[Column_name].unique() but it returns nan as one of the elements. what can i do to just ignore the missing values. dataframe look like this.click...
more »

2017-06-21 18:06 (1) Answers

How to write DataFrame-friendly functions

Recently I've been making the switch from using numpy's ndarray to pandas' DataFrame for my data analysis needs. I've noticed that numpy functions seem to accept DataFrame objects in place of ndarray without issue. However, when I try to use many of ...
more »

2017-06-20 16:06 (1) Answers

Python O365 Sending Email

I am trying to use the dataframe of an email rolodex to iterate an attachment and coverletter to the amount of indexes found in the dataframe. Can anyone tell me how i reference the specific column through i below for each setting? thanks body_of_e...
more »

2017-06-19 22:06 (1) Answers

replace values by the mean

I have a dataframe as follow: Col1 Price 1 Plastic 50 2 Metal 100 3 Plastic 40 I would like to replace values in Col1 by their means in Price, So I get: Col1 Price 1 45 ...
more »

2017-06-19 18:06 (3) Answers

Python - Pandas Indexing and Selecting

I am trying to get pandas to select the range of rows under the "ClosePrice" from the below structured csv and store it in dataframes. The file has many identifiers but I only want to go through the file with the identifiers in the list below. Also t...
more »

2017-06-18 20:06 (1) Answers

Currency conversion in pandas

I am trying to convert values with different currency to "USD" currency. I tried easymoney and CurrencyConvertor packages but those do not seem to work with dataframe python. It seems working if I do conversion row by row using iloc but that is taki...
more »

2017-06-18 20:06 (1) Answers

Remove anti-aliasing for pandas plot.area

I want to plot stacked areas with Python, and find out this Pandas' function: df = pd.DataFrame(np.random.rand(10, 4), columns=['a', 'b', 'c', 'd']) df.plot.area(); However, the result is weirdly antialiased, mixing together the colors, as shown o...
more »

2017-06-18 09:06 (2) Answers

Turn a string back into a datetime timedelta

A column in my pandas data frame represents a time delta that I calculated with datetime then exported into a csv and read back into a pandas data frame. Now the column's dtype is object whereas I want it to be a timedelta so I can perform a groupby ...
more »

2017-06-18 05:06 (3) Answers

Calculating Percentile in Python Pandas Dataframe

I'm trying to calculate the percentile of each number within a dataframe and add it to a new column called 'percentile'. This is my attempt: import pandas as pd from scipy import stats data = {'symbol':'FB','date':['2012-05-18','2012-05-21','2012...
more »

2017-06-18 05:06 (1) Answers

Pandas: Count the first consecutive True values

I am trying to implement a function that identifies the first consecutive occurrences in a Pandas Series, which has already been masked with the condition I wanted: (e.g.) [True, True, True, False, True, False, True, True, True, True] I want the ab...
more »

2017-06-18 04:06 (4) Answers

Loading .txt fails on Linux but works fine on mac

url = "http://download.cms.gov/some_filename_.zip" dest_dir = "dataset" filename = dest_dir + "/" + url.split("/")[-1].split(".")[0]+".txt" drugs = pd.read_table(filename) Above lines work fine on mac os but somehow fail on Linux. When I print ...
more »

2017-06-17 21:06 (0) Answers

Pandas replace column values with a list

I have a dataframe df where some of the columns are strings and some are numeric. I am trying to convert all of them to numeric. So what I would like to do is something like this: col = df.ix[:,i] le = preprocessing.LabelEncoder() le.fit(col) newCol...
more »

2017-06-17 21:06 (1) Answers

Grouping columns by unique values in Python

I have a data set with two columns and I need to change it from this format: 10 1 10 5 10 3 11 5 11 4 12 6 12 2 to this 10 1 5 3 11 5 4 12 6 2 I need every unique value in the first column to be on its own row. I am a beginner...
more »

2017-06-17 17:06 (5) Answers

How to add two DataFrame

I have DataFrame number 1 Price Things 0 1 pen 1 2 pencil 2 6 apple I have DataFrame number 2: Price Things 0 5 pen 1 6 pencil 2 10 cup I want to join two DataFrames and I'd like to see this DataFram...
more »

2017-06-17 17:06 (3) Answers

Parsing Last Name from Name in Python

Trying to determine a single last name. names = ["John Smith", "D.J. Richies III","AJ Hardie Jr.", "Shelia Jackson-Lee", "Bob O'Donnell"] Desired Output last_names = ['Smith', 'Richies','Hardie','Lee', 'ODonnell' ] I'm hoping there is an existi...
more »

2017-06-17 15:06 (3) Answers

Python Pandas TypeError: cannot do label indexing

I have some codes for detecting a specific level of values and want it to be returned to 0 or 1. I imported the data using Python Pandas and tried to do it from there. However when the code is run, it returned some type error as following: import p...
more »

2017-06-17 14:06 (0) Answers

groupby column while showing other columns

I have a dataset as follows: name | $ | letter adam, 34, c beny, 45, e adam, 55, a beny, 87, t I'd like to extract the max $ donated by each name, with the respective letter. So for Adam, I would get: adam,55,a. If I use: df.groupby('name')[...
more »

2017-06-17 07:06 (1) Answers