change column name in pandas, which will be used to change name for 1 column

df.loc[((df.SPIN == ‘COR’) | (df.SPIN == r’F/R’)), ‘MTM’] = (df[“MARKET PRICE”] – df[“TRADE PRICE”]) * ( df[“QTY”] / 100) df.rename(columns={‘MTM’: ‘Market to Market’}, inplace=True) reportName = “Output” reportFileOut = rptDirPath + ‘\\’ + reportName + ‘.xlsx’ writer = pd.ExcelWriter(reportFileOut) df.to_excel(writer, ‘Sheet1’) writer.save()

how can I loop to get the list named vlist?

Check this out. List Comprehension import numpy as np import pandas as pd df = pd.read_csv(‘census.csv’) data = [‘SUMLEV’,’STNAME’, ‘CTYNAME’, ‘CENSUS2010POP’] df=df[data] adf = df[df[‘SUMLEV’]==50] adf.set_index(‘STNAME’, inplace=True) states = np.array(adf.index.unique()) vlist=[adf.loc[states[i]][‘CENSUS2010POP’].sort_values(ascending =False).head(3).sum() for i in range(0,7)]

Python – Pairwise count items

Try this: b[‘col3’] = (b[‘col1’] + ‘-‘ + b[‘col2’]) print(b.groupby(‘col3’).size()) Output: a-b 2 b-a 2 c-d 1 d-c 1 EDIT 1 Based on your input data (as in comments), here is the df I made up and the results Code: df[[‘seller_city’,’customer_city’]] Output: seller_city customer_city 0 volta redonda sao jose dos pinhais 1 volta redonda sao … Read more

How to write this code without using pandas?

You can simply use the csv module from the standard library: import csv with open(‘__.csv’, ‘r’, newline=””) as f: reader = csv.reader(f) _ , *header = next(reader) d = {} for k, *row in reader: d[k] = dict(zip(header, row)) print(d) {‘reviews’: {‘JOURNAL_IMPACT_FACTOR’: 27.324, ‘IMPACT_FACTOR_LABEL’: ‘Highest’, ‘IMPACT_FACTOR_WEIGHT’: 37.62548387}, ‘hairdoos’: {‘JOURNAL_IMPACT_FACTOR’: 40.0, ‘IMPACT_FACTOR_LABEL’: ‘middle’, ‘IMPACT_FACTOR_WEIGHT’: 50.0}, ‘skidoos’: … Read more

How do I make a function in python which takes a list of integers as an input and outputs smaller lists with only two values?

If you only want groups of two (as opposed to groups of n), then you can hardcode n=2 and use a list comprehension to return a list of lists. This will also create a group of one at the end of the list if the length of the list is odd: some_list = [‘a’,’b’,’c’,’d’,’e’] [some_list[i:i+2] … Read more