I am trying to export my data to an excel file. My problem is that my data comes from a itertools.combination and I cannot figure out how to export all of the combinations and their data into an excel file
My subset comes from an input file that looks like
carbon_1 xcoordinate ycoordinate zcoordinate
For n number of carbons
For reference, my code is
subset = cmd[['carbon','x_coord', 'y_coord','z_coord']]
coordinate_values = [tuple(x) for x in subset.values]
atoms = coordinate_values
atomPairs = itertools.combinations(atoms, 2)
atoms_dict = {k:"carbon_{}".format(i) for i,k in enumerate(atoms,1)}
print("Computing distance between {} and {}".format(atoms_dict[pair[0]],atoms_dict[pair[1]]))
I then have a simple definition to calculate distance, d, and the end of my code is
if d >= 1.4 and d < 1.6:
bond = 1
elif d >= 1.2 and d < 1.4:
bond = 2
elif d >= 1 and d < 1.2:
bond = 3
else:
bond = 0
The output of my code for each combination is
Computing distance between carbon_1 and carbon_2
2
I would like to be able to export the 'bond' for each combination into an excel sheet. The excel sheet would be able to grow if I add another coordinate to the combination, aka another 'carbon'. The excel sheet would look something like this:
"Carbon pair" "Bond"
Carbon 1 to Carbon 2 2
Carbon 2 to Carbon 3 3
I am very new to Python and I am unsure how to export anything into excel, let alone create a table in excel that will satisfy these conditions. Suggestions would be greatly appreciated.

openpyxlis a very good python module: openpyxl.readthedocs.io/en/default