Access specific column in Pandas DataFrame
import pandas as pd df: pd.DataFrame = pd.read_csv("avocado.csv") print(df["AveragePrice"])
References
https://pythonprogramming.net/introduction-python3-pandas-data-analysis/
import pandas as pd df: pd.DataFrame = pd.read_csv("avocado.csv") print(df["AveragePrice"])
References
https://pythonprogramming.net/introduction-python3-pandas-data-analysis/
Create two data frames and append the second to the first one
# Importing pandas as pd import pandas as pd # Creating the first Dataframe using dictionary df1 = df = pd.DataFrame({"a":[1, 2, 3, 4], "b":[5, 6, 7, 8]}) # Creating the Second Dataframe using dictionary df2 = pd.DataFrame({"a":[1, 2, 3], "b":[5, 6, 7]}) # Print df1 print(df1, "\n") # Print df2 df2
Now append df2 at the end of df1.
# to append df2 at the end of df1 dataframe df1.append(df2)
Notice the index value of second data frame is maintained in the appended data frame. If we do not want it to happen then we can set ignore_index=True.
# A continuous index value will be maintained # across the rows in the new appended data frame. df.append(df2, ignore_index = True)
References
https://www.geeksforgeeks.org/python-pandas-dataframe-append/
Pandas uses the xlwt
Python module internally for writing to Excel files.
movies.to_excel('output.xlsx')
You can choose to skip the index by passing along index-False.
movies.to_excel('output.xlsx', index=False)
We can do use these advanced output options by creating a ExcelWriter
object and use this object to write to the EXcel file.
writer = pd.ExcelWriter('output.xlsx', engine='xlsxwriter') movies.to_excel(writer, index=False, sheet_name='report') workbook = writer.bookworksheet = writer.sheets['report']
header_fmt = workbook.add_format({'bold': True}) worksheet.set_row(0, None, header_fmt)
writer.save()
# importing pandas module import pandas as pd # making data frame data = pd.read_csv("https://media.geeksforgeeks.org/wp-content/uploads/nba.csv") # dataframe.size size = data.size # dataframe.shape shape = data.shape # dataframe.ndim df_ndim = data.ndim # series.ndim series_ndim = data["Salary"].ndim # printing size and shape print("Size = {}\nShape ={}\nShape[0] x Shape[1] = {}". format(size, shape, shape[0]*shape[1])) # printing ndim print("ndim of dataframe = {}\nndim of series ={}". format(df_ndim, series_ndim))
Size = 4122 Shape=(458, 9) Shape[0] x Shape[1] = 4122 ndim of dataframe = 2 ndim of series=1
References
https://www.geeksforgeeks.org/python-pandas-df-size-df-shape-and-df-ndim/
import configparser config = configparser.ConfigParser() config.read('example.ini') config['DEFAULT']['Compression']
References
https://docs.python.org/3/library/configparser.html
import ntpath import os filename = "templates - original/001.png" print(ntpath.basename(filename)) print(os.path.basename(filename)) print(os.path.split(filename)) print(os.path.splitext(filename)) print(os.path.splitext(os.path.basename(filename))) print(os.path.splitext(os.path.basename(filename))[0])
output
001.png 001.png ('templates - original', '001.png') ('templates - original/001', '.png') ('001', '.png') 001
# import pandas package as pd import pandas as pd # Define a dictionary containing students data data = {'Name': ['Ankit', 'Amit', 'Aishwarya', 'Priyanka'], 'Age': [21, 19, 20, 18], 'Stream': ['Math', 'Commerce', 'Arts', 'Biology'], 'Percentage': [88, 92, 95, 70]} # Convert the dictionary into DataFrame df = pd.DataFrame(data, columns = ['Name', 'Age', 'Stream', 'Percentage']) print("Given Dataframe :\n", df) print("\nIterating over rows using iterrows() method :\n") # iterate through each row and select # 'Name' and 'Age' column respectively. for index, row in df.iterrows(): print (row["Name"], row["Age"])
References
https://www.geeksforgeeks.org/different-ways-to-iterate-over-rows-in-pandas-dataframe/
import pandas as pd
excel_file = 'movies.xls' movies = pd.read_excel(excel_file)
movies_sheet1 = pd.read_excel(excel_file, sheetname=0, index_col=0)
window.scroll({ top: 100, left: 100, behavior: 'smooth' });
var elmnt = document.getElementById("content"); elmnt.scrollIntoView();
var elmnt = document.getElementById("myDIV"); var x = elmnt.scrollLeft; var y = elmnt.scrollTop;
References
https://developer.mozilla.org/en-US/docs/Web/API/Window/scroll
https://www.w3schools.com/jsref/met_element_scrollintoview.asp
https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView
https://www.w3schools.com/jsref/prop_element_scrolltop.asp
https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollTop
<textarea #someVar id="tasknote" name="tasknote" [(ngModel)]="taskNote" placeholder="{{ notePlaceholder }}" style="background-color: pink" (blur)="updateNote() ; noteEditMode = false " (click)="noteEditMode = false"> {{ todo.note }} </textarea>
import {ElementRef,Renderer2} from '@angular/core'; @ViewChild('someVar') el:ElementRef; constructor(private rd: Renderer2) {} ngAfterViewInit() { console.log(this.rd); this.el.nativeElement.focus(); // we can access it after ngAfterViewInit }
References
https://stackoverflow.com/questions/38944725/how-to-get-dom-element-in-angular-2