A dataframe in Python is a two-dimensional labeled data structure with columns of potentially different types. It is similar to a spreadsheet or SQL table, or a dictionary of Series objects. It is one of the most commonly used data structures in data analysis and data science.

A dataframe can be created using various methods such as reading data from a CSV file, constructing a dataframe from a dictionary, or using the pandas library.

Example:

import pandas as pd

# create a dataframe from a dictionary
data = {'Name': ['John', 'Jack', 'Mary', 'Anna'],
        'Age': [25, 30, 28, 32],
        'Gender': ['Male', 'Male', 'Female', 'Female']}
df = pd.DataFrame(data)

# display the dataframe
print(df)

Output:

   Name  Age  Gender
0  John   25    Male
1  Jack   30    Male
2  Mary   28  Female
3  Anna   32  Female

In this example, we created a dataframe from a dictionary containing the name, age, and gender of four individuals. We then used the pandas library to create a dataframe object and displayed it

python Dataframe

原文地址: https://www.cveoy.top/t/topic/cv4z 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录