
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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 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
Advertisements