How to use Pandas DataFrames
• 1 minTo use Pandas DataFrames, you first need to install the pandas library by running pip install pandas
in your terminal or command prompt. Then, you can import pandas into your script and use it to create, manipulate and analyze data stored in dataframes.
Here are some common operations you can perform using Pandas DataFrames:
- Creation: Create a DataFrame from a dictionary, list, or CSV file using pandas.DataFrame()
- Indexing/Selection: Select data using labels (loc) or positions (iloc)
- Sorting: Sort data by one or multiple columns
- Filtering: Filter data using boolean indexing
- Grouping: Group data and aggregate using functions such as sum() or mean()
- Transformation: Apply functions to data to transform it, such as using the apply() method or map()
- Cleaning: Clean and pre-process data by handling missing values, converting data types, etc.
- Visualization: Plot data using functions such as plot() or hist().
Here's a simple example to create a DataFrame from a dictionary and access the data:
import pandas as pd
data = {'Name': ['John', 'Jane', 'Jim', 'Joan'],
'Age': [30, 29, 31, 33],
'City': ['New York', 'London', 'Paris', 'Berlin']}
df = pd.DataFrame(data)
print(df)
This will output:
Name Age City
0 John 30 New York
1 Jane 29 London
2 Jim 31 Paris
3 Joan 33 Berlin
If you want to know more about DataFrames and their capabilities you can find a lot of ressources here: