473,383 Members | 1,748 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

How do I split a column of a csv file in excel using python 3.3?

gesqo
7
I have a column of some hundreds rows, obtained by a python program,each cell containing 4 unequal (in length) strings,like:
adfhyhh ihhgfdtykk red piuol
How can I split it with python in 4 colomns,with each cell containing one string?
Thanks.
Nov 22 '12 #1
6 7918
bvdet
2,851 Expert Mod 2GB
Perhaps I don't understand your question. It is somewhat vague.
Expand|Select|Wrap|Line Numbers
  1. >>> cell = "adfhyhh ihhgfdtykk red piuol"
  2. >>> columns = cell.split()
  3. >>> columns
  4. ['adfhyhh', 'ihhgfdtykk', 'red', 'piuol']
  5. >>> 
Nov 22 '12 #2
gesqo
7
This is a better illustration of what I need:
A B C D E
1 adfhyhh*ihhgfdtykk*red*piuol adfhyhh ihhgfdt red piuol
2 ehethe tthy tytuiuu aaaaaaa ehethe tthy tytu aaaaa


Attached Images
File Type: jpg ScreenShotexcel.jpg (10.2 KB, 2731 views)
Nov 22 '12 #3
bvdet
2,851 Expert Mod 2GB
You can directly read the Excel workbook contents with xlrd, and the data is formatted so you can access the cell elements. What does your data look like after is is read by "a python program"?
Nov 23 '12 #4
gesqo
7
I didn't say «read by a python program»,so I don't undrestand well your question.
If you meant how I created the cv file:with «f.write('file.csv','w')».
I expect a solution smth like «column.split».
Nov 23 '12 #5
bvdet
2,851 Expert Mod 2GB
"What does your data look like?" Since you don't understand me and I don't understand you, I'll take a guess.
Expand|Select|Wrap|Line Numbers
  1. data = """3d3cd455 c6dd 4390 08712b657ec7
  2. 6b9754c7 761f 4b76 fe0c41e1fecb
  3. 05a9bd30 69c3 4631 73916e968dfe
  4. 047db4fd 3bb3 4bec 719313b2928b
  5. db9e189c 0c8b 4fb0 b1c1d20e8d49
  6. 3427aeca d649 4286 4e2df66de67b
  7. 037189cd 63ec 4d5c bb7b8255c169
  8. e95a4329 98d8 4ab3 1f4e902c147e
  9. 376773f8 a7da 4915 ec20af56c02b"""
You can create 4 columns in each row by replacing the space character with a comma.
Expand|Select|Wrap|Line Numbers
  1. data = data.replace(" ", ",")
If you want to do it in a more complicated way:
Expand|Select|Wrap|Line Numbers
  1. "\n".join([",".join(item.split()) for item in data.split("\n")])
Nov 23 '12 #6
gesqo
7
Thank you.Seems working.
Nov 23 '12 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Danielsen Brian \(IFR Contractor External\) | last post by:
Does anyone know how to do file navigation between drives? I know how to navigate up and down within a drive (for example the C:\ drive), but I don't know how to change drives. I'm looking for...
0
by: mark | last post by:
Is there any way to guess the file type using python? thanks mark For example in unix: file code.py code.py: a python script text executable file Eccentric.gif
7
by: Chi Yin Cheung | last post by:
Hi, Is there a way in python to output binary files? I need to python to write out a stream of 5 million floating point numbers, separated by some separator, but it seems that all python supports...
1
by: Girish | last post by:
Hi, I want to embed a txt document into an excel using python. Here is my code, but i get an error message =================================================== Traceback (most recent call...
2
by: padmashreeg | last post by:
Hi, How to embed object in excel using python? Thanks, padma
2
by: skulka3 | last post by:
Hello, I want to implement file downloads inside an authenticated web page, such that when a user clicks a link, the server side python code connects to a ftp server, downloads a relevant file...
1
by: CORVID6116 | last post by:
Hi Guys, I can read and write .XLS files using Python. But now i need to write an XLS file with conditional formatting on some of the cells. Any help would be appreciated. Thanls
1
by: alivip | last post by:
How to brows and select a directory of file by using python TKinter like brows to find attachment in email but I can select not only file but whole directory any help
1
by: idealfellow | last post by:
Hi All, I need to delete entire column(GB) in excel using ruby code. let me whether i should write some ruby code or is there a way to call an excel macro from ruby whichever is simpler...
3
by: loudey | last post by:
I'm trying to split a product code into multiple cells but i'm not sure how to go about it. here is an example (the product code is in A1) A1=MST5F2 Here is what i want the output to look...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.