Pandas DataFrames
Pandas DataFrames
Dark mode
Dark code
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP BOOTSTRAP HOW TO W3.CSS C C++ C# REACT R JQUERY DJANGO
Pandas HOME
Pandas Intro
Pandas Getting Started
Pandas DataFrames
Pandas Series
Pandas DataFrames
Pandas Read CSV
Pandas Read JSON ❮ Previous Next ❯
Pandas Analyzing Data
Cleaning Data
Cleaning Data
What is a DataFrame?
Cleaning Empty Cells A Pandas DataFrame is a 2 dimensional data structure, like a 2 dimensional array, or a table with rows and columns.
Cleaning Wrong Format
Cleaning Wrong Data
Removing Duplicates Example Get your own Python Server
Pandas Correlations
import pandas as pd
Plotting data = {
Pandas Plotting "calories": [420, 380, 390],
"duration": [50, 40, 45]
Quiz/Exercises }
Pandas Editor
#load data into a DataFrame object:
df = pd.DataFrame(data)
print(df)
Result
calories duration
0 420 50
1 380 40
2 390 45
COLOR PICKER
Try it Yourself »
Pandas use the loc attribute to return one or more specified row(s)
Example
Return row 0:
Result
calories 420
duration 50
Name: 0, dtype: int64
Try it Yourself »
ADVERTISEMENT
Example
Return row 0 and 1:
Result
calories duration
0 420 50
1 380 40
Try it Yourself »
Get Certified!
school
w3 s
2
CE
02
Complete the Pandas modules, do the exercises, take the exam, and you will become w3schools certified! TI 2
R
FI .
ED
$10 ENROLL
Named Indexes
With the index argument, you can name your own indexes.
Example
Add a list of names to give each row a name:
import pandas as pd
data = {
"calories": [420, 380, 390],
"duration": [50, 40, 45]
}
print(df)
Result
calories duration
day1 420 50
day2 380 40
day3 390 45
Try it Yourself »
Example
Return "day2":
Result
calories 380
duration 40
Name: day2, dtype: int64
Try it Yourself »
Example
Load a comma separated file (CSV file) into a DataFrame:
import pandas as pd
df = pd.read_csv('data.csv')
print(df)
Try it Yourself »
You will learn more about importing files in the next chapters.
Exercise:
Insert the correct Pandas method to create a DataFrame.
pd. (data)
Submit Answer »
ADVERTISEMENT
ADVERTISEMENT
FORUM | ABOUT
W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we
cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy.