Categories
Python Answers

How to create Python Pandas DataFrame from txt file with a specific pattern?

Spread the love

To create Python Pandas DataFrame from txt file with a specific pattern, we can use the read_csv method.

For instance, we write

df = pd.read_csv('filename.txt', sep=";", names=['Region Name'])

to call read_csv with the path of the txt file to read from.

sep is set to the separator for the row items.

And names is the column name of the columns to create.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *