how to read data from multiple sheets in a single csv file using python [closed]

2024/11/9 4:37:01

I am using python and i had a csv file with data in multiple sheets.

So we can read data from csv file using python as below

Suppose the data in data.csv file in sheet1 is below

what    |   are   |  you   | doing | however
hello   |   that  |  would |   be  | usefulcsv_file = "/home/user/csv_folder/data.csv" for line in open(csv_file,'r'):print line....................

The output for the above will be as below

"what are you doing however"
"hello that would be useful"

but in the same data.csv file, i had data in another sheet2 as below

This    |   will   |  be   |   second  | sheet | data
That    |   would  |  lot  |   useful  | now

Now what i am trying to do is to print the data which is present in another sheets(more than 1 sheets if present in a single csv file).

Can anyone let me now how we can print the data in all the sheets present in a single csv file ?

Can anyone please share a bit of python code that process more than one sheet present in a single csv file ?

Answer

There is no concept of "sheets" in csv file like many of the commentators have pointed out correctly.

If you are trying to read "sheets" from an excel file, here is a good blog resource for you to figure out the syntax.

http://michalisavraam.org/2009/06/manipulating-excel-files-using-python-part-1-reading-files/

Do note that if you are indeed intending to read "sheets" from an excel file, the 3rd party package recommended by the above blog link xlrd needs to be separately downloaded and installed in your system. Like this:-

pip install xlrd

before you can import xlrd in your python script as recommended by the blog post.

https://en.xdnf.cn/q/120527.html

Related Q&A

Quality Center: Set a Step Field in Python

I have a very simple problem here. I want to achieve the following VB script Code in Python:- dim objSfact dim objOrun dim mystep Set objOrun = QCutil.CurrentRun Set objSfact = objOrun.StepFactory…

Convert for loop from Python to C++ [closed]

Closed. This question needs debugging details. It is not currently accepting answers.Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to repro…

Storing values in a CSV file into a list in python

Id like to create a list that stores all values of a single column. For example lets say my file has a column called FirstNames and for the first 3 rows, the names column has Merry, Pippin, Frodo.Id l…

Python arithmetic quiz task 1

I have no idea why this code is not working, as you can see Im trying to ask the user 10 questions display their score at the end. Everything works except that the score will always appear as a 0 or 1 …

Using Python to split long string, by given ‘separators’ [duplicate]

This question already has answers here:Split Strings into words with multiple word boundary delimiters(31 answers)Closed 9 years ago.Environment: Win 7; Python 2.76I want to split a long string into pi…

How do I return the number of unique digits in a positive integer

Example: unique_dig(123456) All unique 6Im trying to write code to have a function return how many unique numbers there are in a positive integer.count = 0for i in unique_digits:if count.has_key(i):cou…

Python check json file with variables

I have a json file which has 18 substrings like this: https://i.sstatic.net/aVWuw.png https://i.sstatic.net/RLlRX.pngBut I have more json files who have different number of these substrings. So I did t…

The Sum of Consecutive Numbers in Python

What I have to do is get the user input and add consecutive numbers starting with one using a loop until the sum equals or exceeds the input. Its an exercise, so Im trying to do this without using the …

how to write to a text file using python ?

I am trying to output a full for iteration. The output should be in a text file. How should I code for that ? The output should look like :Iteration 1 values --------> val1 < tab > val2 < …

Python: Sorting dictionary by key

I am trying to sort a dictionary by key.If I do the following, then the dictionary is sorted like this1, 20 10, 5 11, 3 2, 30 20, 2Instead, I wanted to sort it like the following:1, 20 2, 30 10, 5 11, …