DEV Community

Ramya .C
Ramya .C

Posted on

Day 48 of Data Analytics Pandas & Java Arrays !

Today, I explored Pandas in Python and Arrays in Java. Here's what I learned and practiced:

1. Assigning Index in Pandas

You can set a custom index for a DataFrame instead of the default numeric index.

import pandas as pd

data = {'Name': ['Raj', 'Ashok', 'Aruna'], 'Age': [39, 20, 20]}
df = pd.DataFrame(data)
df.index = ['a', 'b', 'c']
print(df)
Enter fullscreen mode Exit fullscreen mode

Output:

      Name  Age
a      Raj   39
b    Ashok   20
c    Aruna   20
Enter fullscreen mode Exit fullscreen mode

2. Resetting Index

Reset index to default numeric values.

df_reset = df.reset_index()
print(df_reset)
Enter fullscreen mode Exit fullscreen mode

Output:

  index    Name  Age
0     a     Raj   39
1     b   Ashok   20
2     c   Aruna   20
Enter fullscreen mode Exit fullscreen mode

3. Accessing Data

Access a single column or row:

print(df['Name'])   # Access column
print(df.loc['b'])  # Access row with index 'b'
Enter fullscreen mode Exit fullscreen mode

4. Filtering & Slicing

Filter rows based on condition:

print(df[df['Age'] > 20])  # Age greater than 20
Enter fullscreen mode Exit fullscreen mode

Slice rows:

print(df[0:2])  # First 2 rows
Enter fullscreen mode Exit fullscreen mode

5. True or False Filtering

Check conditions for each row:

print(df['Age'] > 20)
Enter fullscreen mode Exit fullscreen mode

Output:

a     True
b    False
c    False
Name: Age, dtype: bool
Enter fullscreen mode Exit fullscreen mode

6. Capitalize First Letter of Each Word

sentence = "this is my today contente make it for post"
capitalized_sentence = sentence.title()
print(capitalized_sentence)
Enter fullscreen mode Exit fullscreen mode

Output:

This Is My Today Contente Make It For Post
Enter fullscreen mode Exit fullscreen mode

7. Arrays in Java

Basic usage of arrays in Java:

public class ArrayExample {
    public static void main(String[] args) {
        int[] numbers = {10, 20, 30, 40};

        // Accessing array elements
        System.out.println(numbers[2]);  // 30

        // Looping through array
        for(int num : numbers){
            System.out.println(num);
        }
    }
}
Enter fullscreen mode Exit fullscreen mode

Output:

30
10
20
30
40
Enter fullscreen mode Exit fullscreen mode

Today’s focus was on data manipulation in Python using Pandas and understanding arrays in Java. These are fundamental skills for data analytics and programming.

Top comments (0)