Welcome folks today in this blog post we will be converting the content of text file to csv file using the pandas
library in python. All the full source code of the application is shown below.
Get Started
In order to get started you need to install the below pandas module using the pip
command as shown below
pip install pandas
And after that you need to make an app.py
file and copy paste the following code
app.py
1 2 3 4 5 6 |
# importing panda library import pandas as pd dataframe1 = pd.read_csv("users.txt") dataframe1.to_csv('users.csv',index = None) |
As you can see we are importing the pandas
module and then we are simply reading
the input text file content using the read_csv()
method and then storing it inside the dataframe1
variable and then we are converting the text file data to csv
format using the to_csv()
method. And in this we are passing the output
csv file name and also we are providing the second argument index
value equal to None. And now if you execute the python
script in the command line it will convert the text file to csv and store it locally as shown below