Answer the question
In order to leave comments, you need to log in
How to find all rows under another one?
In general, I need to make a graph from the data in the document. That is, I need to find all the data under the symbol X and Y, and then write them to json. Well, there are no problems with json, but how to find all the words under the string: "X" I have no idea. If someone can help I will be very happy!
the data in the document looks something like this:
XY
1 1
2 2
3 3
4 4
5 5
Answer the question
In order to leave comments, you need to log in
Well, if this is the format:
import csv, io, json
data = '''X Y
1 1
2 2
3 3
4 4
5 5'''
f = io.StringIO(data)
reader = csv.DictReader(f, delimiter=' ')
json.dumps(list(reader))
# '[{"X": "1", "Y": "1"}, {"X": "2", "Y": "2"}, {"X": "3", "Y": "3"}, {"X": "4", "Y": "4"}, {"X": "5", "Y": "5"}]'
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question