Dictionary from data frame. Values assigned to tuple keys derived from column, row products

Given a data frame structured as follows: df = pd.DataFrame({ ‘DATE’ : [1,2,3,4,5], ‘Q24’ : [23.28, 28.81, 29.32, 29.8, 30.25], ‘J24’ : [24.22, 24.89, 25.54, 26.15, 26.73], ‘F24’ : [22.34, 32.73, 33.1, 33.45, 33.77] }) I would like to create a dictionary in which all keys are tuples containing the products of values in df[‘DATES’]… Read More Dictionary from data frame. Values assigned to tuple keys derived from column, row products

An apply function in pandas to create a column based on conditions in a column

I’m working up some data where I’ve looked at data and created a flag column because I want to provide a column (I’ve called it result although this is my aim) where it is empty top_tier is empty or returns the parent region. I’ve tried ffill and apply but I can’t get the result. Update:… Read More An apply function in pandas to create a column based on conditions in a column

Changing cell values of a pandas dataframe

I have below data frame import pandas as pd dat1 = pd.DataFrame({‘x’ : [1,2,4], ‘y’ : [3,4,10]}).set_axis([‘a’, ‘b’, ‘c’], axis = 0) Now I want chance values of certain cells by calling those cells by name. I tried below dat1.iloc[‘b’][‘y’] = 999 However this generates error as below, >>> dat1.iloc[‘b’][‘y’] = 999 Traceback (most recent… Read More Changing cell values of a pandas dataframe

pandas to_csv using latin script Ç as separator?

My team uses a Ç (ALT 0199) as a separator in their CSV files. I’m trying to replicate using this in Pandas, but not having any luck. Any guidance is appreciated as I’m new to Pandas results.to_csv(‘filename.csv’, encoding=’latin1′, sep=’Ç’) SyntaxError: (unicode error) ‘utf-8’ can’t decode byte 0xc7 >Solution : The fact that you get a… Read More pandas to_csv using latin script Ç as separator?