Pandas Reading Each Xlsx File In Folder Code Example

Snippet 1 import sys import csv import glob import pandas as pd # get data file names path =r’C:DRODCL_rawdata_filesexcelfiles’ filenames = glob.glob(path + “/*.xlsx”) dfs = [] for df in dfs: xl_file = pd.ExcelFile(filenames) df=xl_file.parse(‘Sheet1’) dfs.concat(df, ignore_index=True) Snippet 2 import os import pandas as pd import openpyxl as excel import glob #setting up path path… Continue reading Pandas Reading Each Xlsx File In Folder Code Example

Read All Files And Store In One Dataframe Pandas Code Example

Snippet 1 path = r’C:DRODCL_rawdata_files’ # use your path all_files = glob.glob(os.path.join(path, “*.csv”)) # advisable to use os.path.join as this makes concatenation OS independent df_from_each_file = (pd.read_csv(f) for f in all_files) concatenated_df = pd.concat(df_from_each_file, ignore_index=True) Copyright © Code Fetcher 2020    

Pandas Drop Rows With Condition Code Example

Snippet 1 # import pandas library import pandas as pd    # dictionary with list object in values details = {     ‘Name’ : [‘Ankit’, ‘Aishwarya’, ‘Shaurya’,               ‘Shivangi’, ‘Priya’, ‘Swapnil’],     ‘Age’ : [23, 21, 22, 21, 24, 25],     ‘University’ : [‘BHU’, ‘JNU’, ‘DU’, ‘BHU’,                      ‘Geu’, ‘Geu’], }    # creating a Dataframe object  df = pd.DataFrame(details,… Continue reading Pandas Drop Rows With Condition Code Example

Pandas Groupby Mean Code Example

Snippet 1 df.groupby([‘A’, ‘B’]).mean() Snippet 2 In [57]: df.groupby([‘cluster’, ‘org’]).mean() Out[57]: time cluster org 1 a 438886 c 23 2 d 9874 h 34 3 w 6 Copyright © Code Fetcher 2020    

Pandas Iterrows Code Example

Snippet 1 >>> df = pd.DataFrame([[1, 1.5]], columns=[‘int’, ‘float’]) >>> row = next(df.iterrows())[1] >>> row int 1.0 float 1.5 Name: 0, dtype: float64 >>> print(row[‘int’].dtype) float64 >>> print(df[‘int’].dtype) int64 Snippet 2 for index, row in flights.head(n=2).iterrows():      print(index, row) Snippet 3 for index, row in df.iterrows(): print(row[‘c1’], row[‘c2’]) Snippet 4 for index, row in df.iterrows(): print(row[‘c1’],… Continue reading Pandas Iterrows Code Example

Pandas Correlation Function Code Example

Snippet 1 # importing pandas as pd import pandas as pd    # Making data frame from the csv file df = pd.read_csv(“nba.csv”)    # To find the correlation among # the columns using kendall method df.corr(method =’kendall’) Snippet 2 # To find the correlation among # the columns using pearson method df.corr(method =’pearson’) Copyright… Continue reading Pandas Correlation Function Code Example