Pandas read into a single column - pandas

I am reading from a .txt file into a dataframe using pandas read_csv(). The data is in this form in the txt file (this is a sample):
abcd,efgh,ijklm
qwerty,uoipqwrt
mznxlakspqowieu
As you can see there are different number of commas in each line. But ultimately I want to put each line of the text file in a single column. How can this be achieved?

Related

Error in appending first row of a dataframe to a csv file template

Trying to append the dataframe to an existing template of a csv file.
Facing problem with the first row data only. Instead of first row being written in second row below the column fields, it is getting written adjacent to column headings with the last column heading getting merged with the first row data. Unable to resolve it. I'm seeking help to resolve this issue.
import shutil, pandas as pd
original_File = 'File1.csv'
target_File = "File2.csv"
shutil.copyfile(original_File, target_File)
FinalDF = pd.DataFrame()
FinalDF["Item"]= None
FinalDF["Value"] = None
FinalDF.loc["0"] = ["Book",300]
FinalDF.loc["1"] = ["Calculator",1000]
print(FinalDF)
FinalDF.to_csv('File2.csv',mode='a', index=False, header=False)
The issue was with the template file. On opening the template csv file in mac book, it was keeping the cursor active in the last column heading cell even after closing it.
When the dataframe is appended to the file2 which is a replica of File1, first row is continued from last column heading cell but succeeding rows are appended normally.
Hence i tried to open the same csv file in windows system, for the safer side, deleted all extra columns and rows in the template file and saved.
Thereafter not facing this issue.

How to read CSV in Pandas data frame when each cell has the header label?

I am trying to read a log file CSV that has header labels in each cell. Is there an elegant way to do it apart from column by column handling of strings and removing the labels?

Missing header values while using to_csv function

I am trying to read excel files using python and writing each sheet's data into separate csv file.
I am able to write the whole data but its just I am unable to get the header values.
Is there any way this can be resolved.
Here is the piece of code I am writing.
xyz.to_csv(f, index=False, header=None)

How to read a txt file and use its data to compare it with other variables?

I want to create a program, which reads 2 txt files. The first txt file is a logfile, the second is a short one with names. The task is to read both of the files, and count the specific names(from the second txt) in the first txt.

Finding occuramce of a string in a column in excel based text file

I am using vb.net to find the sum of occuramce of string in a particular column in text file(excel based) . The text file is not tab delimited, and it is separated column by column nicely, I only learnt how to read line by line using stream reader but I have no idea how to read only the last column of the line and summing up the specific string that I want. Any idea how to do it? Not nesseccary nid to provide me the code
If by "an Excel-based text file" you mean that the values are comma-separated, you can read it in line by line, like you already are doing using a stream, and then use Split to separate the line out into an array. Google "vb.net split" to learn how to do this.