I call the oxidation states of A and B in AB compounds from list1 (‘CaFe’, ‘BaSi’, ‘SeOs’, ‘BaGeO’, ‘CdCe’):
dfA = pd.read_csv("oxi_state.csv",index_col=0, header =0)
A1 = []
A2 = []
final = []
for i in range(len(list1)):
A1 = dfA['OS'][list1[i][0]]
A2 = dfA['OS'][list1[i][1]]
A = (A1, A2)
final.append(A)
final
When I have called the data from DataFrame. The data is in the form:
[('2', '2,3,4'),
('2', '4'),
('-2,4,6', '4,5,6,7'),
('2', '2,4'),
('2', '3,4')]
Now I want to convert in the following form:
[([2], [2, 3, 4]), ([2], [4]), ([-2,4,6], [4,5,6,7]), ([2], [2,4]), ([2], [3,4])]
For post processing.
Thanks in advance
4
Answers
you may have to loop through all of the items. Using
will return
You can then go through and remove the commas and convert the str to int
Use split method with
,
as a seperator.Here a brute force solution :
It’s unclear how the list of tuples is being created. However, based on the sample shown then:-
Output: