GroupBy results to dictionary of lists

You could groupby on Column1 and then take Column3 to apply(list) and call to_dict? In [81]: df.groupby(‘Column1’)[‘Column3’].apply(list).to_dict() Out[81]: {0: [1], 1: [2, 3, 5], 2: [1, 2], 3: [4, 5], 4: [1], 5: [1, 2, 3]} Or, do In [433]: {k: list(v) for k, v in df.groupby(‘Column1’)[‘Column3’]} Out[433]: {0: [1], 1: [2, 3, 5], 2: … Read more

How to obtain sheet names from XLS files without loading the whole file?

you can use the xlrd library and open the workbook with the “on_demand=True” flag, so that the sheets won’t be loaded automaticaly. Than you can retrieve the sheet names in a similar way to pandas: import xlrd xls = xlrd.open_workbook(r'<path_to_your_excel_file>’, on_demand=True) print xls.sheet_names() # <- remeber: xlrd sheet_names is a function, not a property

writing to existing workbook using xlwt [closed]

Here’s some sample code I used recently to do just that. It opens a workbook, goes down the rows, if a condition is met it writes some data in the row. Finally it saves the modified file. from xlutils.copy import copy # http://pypi.python.org/pypi/xlutils from xlrd import open_workbook # http://pypi.python.org/pypi/xlrd START_ROW = 297 # 0 based … Read more

Reading Excel File using Python, how do I get the values of a specific column with indicated column name?

A somewhat late answer, but with pandas, it is possible to get directly a column of an excel file: import pandas df = pandas.read_excel(‘sample.xls’) #print the column names print df.columns #get the values for a given column values = df[‘Arm_id’].values #get a data frame with selected columns FORMAT = [‘Arm_id’, ‘DSPName’, ‘Pincode’] df_selected = df[FORMAT] … Read more

Create a .csv file with values from a Python list

import csv with open(…, ‘wb’) as myfile: wr = csv.writer(myfile, quoting=csv.QUOTE_ALL) wr.writerow(mylist) Edit: this only works with python 2.x. To make it work with python 3.x replace wb with w (see this SO answer) with open(…, ‘w’, newline=””) as myfile: wr = csv.writer(myfile, quoting=csv.QUOTE_ALL) wr.writerow(mylist)

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)