我在一个文件夹里有一系列.csv文件。 它们中的每一个都有相同的格式,B列标注为 "user_holding"。 我想循环浏览这个文件夹,并打印每个文件中B列的最大值。
import os
import pandas as pd
dirloc = r"C:\Users\username\Documents\folder"
for file in os.scandir(dirloc):
if (file.path.endswith(".csv") or file.path.endswith(".pdf")) and file.is_file():
a = pd.read_csv(file)
b = a['users_holding'].max()
print(b)
感谢任何帮助。 如果需要的话,我很乐意发布更多信息。
你应该试试这个。
import pandas as pd
import os
for file in os.listdir(dirloc):
if (file.endswith(".csv") and os.path.isfile(file)):
file_full_path = os.path.join(dirloc, file)
df=pd.read_csv(file_full_path)
#FINDING MAX value
p=df['ColumnName'].max()
print(p)
它将检查每个 .csv
文件,并使用 pandas
并将打印出特定列的最大值,使用 .max()
功能。
希望对你有帮助...
试试这个。
for file in os.listdir(dirloc):
if file.endswith(".csv") and os.path.isfile(file):
file_full_path = os.path.join(dirloc, file)
df = pd.read_csv(file_full_path)
print(df['users_holding'].max())