Pregunta

I am reading data from a text file and then I do a sort of random walk among the rows. How would you mark a row as "read"?

This is how I'm reading the data:

import pandas as pd
set = pd.read_csv('file.txt', sep=" ", header = None)
set.columns = ["A", "B", "C", "D", "E", "F", "G"]`
¿Fue útil?

Solución

Shuffle the dataframe with numpy using the technique in this question, then iterate over the rows.

so:

df = pd.read_csv('file.txt', sep=" ", header = None)
df.columns = columns = ["A", "B", "C", "D", "E", "F", "G"]
df = df.apply(numpy.random.permutation)

for row in df.iterrows():
    #process row here

Otros consejos

To add a column: data.insert(8, "flag", 0). 0 can be changed to 1 or other values later in the code

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top