Categories
Python Answers

How to rename column names in Python Pandas?

To rename column names in Python Pandas, we call the dataframe rename method.

For instance, we write

df = df.rename(columns={'oldName1': 'newName1', 'oldName2': 'newName2'})

to rename the oldName1 and oldName2 columns to newName1 and newName2 with df.rename.

And then we assign the returned dataframe back to df.

Categories
Python Answers

How to select rows from a DataFrame based on column values with Python Pandas?

To select rows from a DataFrame based on column values with Python Pandas, we can use the loc property.

For instance, we write

df.loc[df['column_name'] == some_value]

to use the df.loc fictionary to get the column value with the df['column_name'] == some_value scalar.

We can combine conditions with & or |.

For instance, we write

df.loc[(df['column_name'] >= A) & (df['column_name'] <= B)]

to return the column values satifying df['column_name'] >= A and df['column_name'] <= B.

Categories
Python Answers

How to iterate over rows in a DataFrame in Python Pandas?

To iterate over rows in a DataFrame in Python Pandas, we can use a for loop.

For instance, we write

import pandas as pd

df = pd.DataFrame({'c1': [10, 11, 12], 'c2': [100, 110, 120]})
df = df.reset_index()  # make sure indexes pair with number of rows
for index, row in df.iterrows():
    print(row['c1'], row['c2'])

to loop through the df dataframe with iterator returned by the df.iterrows method.

We use the row object to get the rows and the keys to get the values.

Categories
React Answers

How to install React Bootstrap?

To install React Bootstrap, we run

npm install react-bootstrap bootstrap

Then in index.js, we add

import 'bootstrap/dist/css/bootstrap.min.css';

to import the CSS.

And in our components, we can add

import { Navbar, Nav, Button } from "react-bootstrap";

to import the components we need.

Categories
React Native Answers

How to use GIFs in rReact Native?

To use GIFs in rReact Native, we add a line to android/app/build.gradle.

For instance, in android/app/build.gradle, we add

dependencies {
  //  ...
  implementation 'com.facebook.fresco:animated-gif:2.5.0'
  //  ...
}

so we can add GIFs into our Android React Native app.