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)
Output:
Name Age
a Raj 39
b Ashok 20
c Aruna 20
2. Resetting Index
Reset index to default numeric values.
df_reset = df.reset_index()
print(df_reset)
Output:
index Name Age
0 a Raj 39
1 b Ashok 20
2 c Aruna 20
3. Accessing Data
Access a single column or row:
print(df['Name']) # Access column
print(df.loc['b']) # Access row with index 'b'
4. Filtering & Slicing
Filter rows based on condition:
print(df[df['Age'] > 20]) # Age greater than 20
Slice rows:
print(df[0:2]) # First 2 rows
5. True or False Filtering
Check conditions for each row:
print(df['Age'] > 20)
Output:
a True
b False
c False
Name: Age, dtype: bool
6. Capitalize First Letter of Each Word
sentence = "this is my today contente make it for post"
capitalized_sentence = sentence.title()
print(capitalized_sentence)
Output:
This Is My Today Contente Make It For Post
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);
}
}
}
Output:
30
10
20
30
40
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)