Pandas Basics

Durum
Üzgünüz bu konu cevaplar için kapatılmıştır...
The sea does not like to be restrained.
Emektar Üye
Katılım
15 Tem 2021
Mesajlar
1,724
Çözümler
86
Tepki puanı
665
Ödüller
10
Yaş
25
Sosyal
4 HİZMET YILI
Pandas is a popular Python library for data manipulation and analysis. It provides a powerful data structure called a DataFrame, which is similar to a spreadsheet or SQL table.

Here's an example of how to create a DataFrame in Pandas:

Python:
import pandas as pd

data = {
    'name': ['Alice', 'Bob', 'Charlie'],
    'age': [25, 30, 35],
    'country': ['USA', 'Canada', 'Mexico']
}

df = pd.DataFrame(data)

print(df)

In this example, we import the Pandas library and create a dictionary data containing information about people. We then use the pd.DataFrame() function to create a DataFrame df from the dictionary.

You can perform various operations on a Pandas DataFrame, such as filtering and sorting data:

Python:
import pandas as pd

data = {
    'name': ['Alice', 'Bob', 'Charlie'],
    'age': [25, 30, 35],
    'country': ['USA', 'Canada', 'Mexico']
}

df = pd.DataFrame(data)

# filter rows where age is greater than 30
filtered_df = df[df['age'] > 30]

# sort by age in descending order
sorted_df = df.sort_values('age', ascending=False)

print(filtered_df)
print(sorted_df)

In this example, we use the [] operator to filter the rows of the DataFrame where the age column is greater than 30, and use the sort_values() function to sort the DataFrame by age in descending order.

You can also perform various data aggregation operations on a Pandas DataFrame:

Python:
import pandas as pd

data = {
    'name': ['Alice', 'Bob', 'Charlie'],
    'age': [25, 30, 35],
    'country': ['USA', 'Canada', 'Mexico']
}

df = pd.DataFrame(data)

# calculate the mean age
mean_age = df['age'].mean()

# group by country and calculate the mean age in each group
grouped_df = df.groupby('country').mean()

print(mean_age)
print(grouped_df)

In this example, we use the mean() function to calculate the mean age of all people in the DataFrame, and use the groupby() function to group the DataFrame by country and calculate the mean age in each group.

Pandas also provides many built-in functions for reading and writing data in various file formats, like CSV, Excel, and SQL databases.
 
Banlı Üye
Katılım
12 Tem 2023
Mesajlar
382
Tepki puanı
21
Yaş
27
2 HİZMET YILI
I’ll make sure to use this in the future if I interested in programming
 
Onaylı Üye
Katılım
5 Şub 2022
Mesajlar
50
Tepki puanı
2
Ödüller
2
Yaş
25
4 HİZMET YILI
import pandas as pd
import numpy as np
df = pd.DataFrame({"station from":[20001,20040,20007,20080, 2, 3],
"station to":[20040,20001,20080,20007, 1, 4],
"count":[55,67,100,50, 20, 40]})
df
 
Donator
Katılım
29 Şub 2024
Mesajlar
40
Tepki puanı
0
Ödüller
2
Yaş
20
2 HİZMET YILI
Very good and useful library for python
 
Onaylı Üye
Katılım
14 Tem 2020
Mesajlar
51
Tepki puanı
1
Ödüller
4
Yaş
30
5 HİZMET YILI
A very useful library for in-memory data processing.
 
Üye
Katılım
25 Şub 2021
Mesajlar
8
Tepki puanı
0
Ödüller
3
Yaş
26
5 HİZMET YILI
Python programlama ve kodlamanın ilk aşamasıdır
 
Durum
Üzgünüz bu konu cevaplar için kapatılmıştır...
Üst