
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Construct a DataFrame in Pandas using string data in Python
Here we will see how we can construct a pandas dataframe using string type data. Pandas supports csv files, but we can do the same using string also. For string type data, we have to use one wrapper, that helps to simulate as the data is taken as csv reader.
Here we are using a string that takes data and separated by semicolon.
Example
Let us see the following implementation to get better understanding −
import pandas as pd from io import StringIO str_data = StringIO("""Id;Subject;Course_Fee 10;DBMS;3000 11;Basic Maths;2000 12;Data Science;40000 13;Algorithm;5000 """) df = pd.read_csv(str_data, sep =";") print(df)
Output
Id Subject Course_Fee 0 10 DBMS 3000 1 11 Basic Maths 2000 2 12 Data Science 40000 3 13 Algorithm 5000
- Related Questions & Answers
- Python – Reshape the data in a Pandas DataFrame
- Python Pandas - Plot multiple data columns in a DataFrame?
- Python - Convert Pandas DataFrame to binary data
- Python Pandas – Remove numbers from string in a DataFrame column
- Frequency plot in Python/Pandas DataFrame using Matplotlib
- Python Pandas - Create a Subset DataFrame using Indexing Operator
- Python - Name columns explicitly in a Pandas DataFrame
- Python - Grouping columns in Pandas Dataframe
- Data analysis using Python Pandas
- Python - Plot a Pandas DataFrame in a Line Graph
- How to append a list to a Pandas DataFrame using loc in Python?
- How to append a list to a Pandas DataFrame using append() in Python?
- How to append a list to a Pandas DataFrame using iloc in Python?
- Write a program in Python Pandas to convert a dataframe Celsius data column into Fahrenheit
- How to check the data type in pandas DataFrame?
Advertisements