Skip to content

Tag: csv

How to print random n rows from a csv file?

So i have a big csv file and my code prints all the rows but i want to print, for example, only 20 random rows from 100000 rows. I know that somehow with random.sample u can do that, but i don’t really know how. Any suggestions? There is my code: Answer I assume you want to randomly sample your data,

Convert a CSV into a JSON using a JSON Schema

How do I convert a flat table into a JSON? I have previously converted JSONs into Flat Tables using both custom code and libraries. However, what I am aiming to do here is the reverse. Before going ahead and creating a custom library, I was wondering if anyone had encountered this problem before and if there …

Splitting a column into 2 in a csv file using python

I have a .csv file with 100 rows of data displayed like this “Jim 1234” “Sam 1235” “Mary 1236” “John 1237” What I’m trying to achieve is splitting the numbers from the names into 2 columns in python edit* Using, I managed to get it to display like this in …

For doesn’t restart on dataframe in python

i need do read the rows of a dataframe but it seems to stop at the first row. I also tried with iterrows but the results are similar. and the outpus is : so the for doesn’t iterate. I hope someone can help me, thank you so much. Answer You are performing inside the loop. This breaks the loop on

how to empty a csv file before writing

Hi I am trying to make a function which writes a table in a csv file. But writerows and writerow just and an another table without clearing the first content(unLike in txt files) here is the class and the program before write_csv function after write_csv fuction As you can see this is not what I want please h…