A pandas DataFrame is a 2D labeled data structure with columns that can be of different types. A DataFrame can be thought of as a dictionary-like container for Series objects, where each key in the dictionary is a column label and each value is a Series.If you are familiar with relational databases,...
Monday, November 21, 2022
Thursday, November 17, 2022
Combining Series into a DataFrame
Multiple Series can be combined to form a DataFrame. Let’s try this by creating another Series and combining it with the emps_names Series: data = ['jeff.russell','jane.boorman','tom.heints']emps_emails = pd.Series(data,index=[9001,9002,9003], name ='emails')emps_names.name = 'names'df = pd.concat([emps_names,emps_emails], axis=1)print(df)To create the new Series, you call the Series() constructor...
Monday, November 14, 2022
Accessing Data in a Series
To access an element in a Series, specify the Series name followed by the element’s index within square brackets, as shown here:print(emps_names[9001])This outputs the element corresponding to index 9001:Jeff RussellAlternatively, you can use the loc property of the Series object:print(emps_names.loc[9001])Although you’re using custom indices in this Series object, you can still access its elements...
Thursday, November 10, 2022
pandas Series
A pandas Series is a 1D labeled array. By default, elements in a Series are labeled with integers according to their position, like in a Python list.However, you can specify custom labels instead. These labels need not be unique, but they must be of a hashable type, such as integers, floats, strings, or tuples.The elements of a Series can be of any type (integers, strings, floats, Python objects,...
Monday, November 7, 2022
Using NumPy Statistical Functions
NumPy’s statistical functions allow you to analyze the contents of an array. For example, you can find the maximum value of an entire array or the maximum value of an array along a given axis.Let’s say you want to find the maximum value in the salary_bonus array you created in the previous post. You can do this with the NumPy array’s max() function:print(salary_bonus.max())The function returns the...
Thursday, November 3, 2022
Performing Element-Wise Operations on NumPy arrays
It’s easy to perform element-wise operations on multiple NumPy arrays of the same dimensions. For example, you can add the base_salary and bonus arrays together to determine the total amount paid each month to each employee:salary_bonus = base_salary + bonusprint(type(salary_bonus))print(salary_bonus)As you can see, the addition operation is a one-liner. The resulting dataset is a NumPy array too,...