简体   繁体   English

有没有办法一次清理 2 个不同 CSV 的 null 数据?

[英]Is there a way to clean the null data of 2 different CSVs at once?

My aim with this is to be able to create one dataframe that will have data from the 2 CSVs in it and also be able to address the rows with null values.我的目标是能够创建一个 dataframe ,其中将包含来自 2 个 CSV 的数据,并且还能够使用 null 值来处理行。

I have 2 CSVs (link to the google sheet), sheet one is nifty, sheet 2 is nsebank.我有 2 个CSV (链接到 google 表),表 1 很漂亮,表 2 是 nsebank。 When I have to clean the sheets individually, I either use dropna or replace null values with say a mean.当我必须单独清洁床单时,我要么使用 dropna,要么用平均值替换 null 值。 Mentioned the code below.提到了下面的代码。

But nifty sheet has 35 null values while nsebank has 305 null values.但是漂亮的表格有 35 个 null 值,而 nsebank 有 305 个 null 值。 Because the null values are different, I wanted to know if there is a way I can read both CSVs in the same dataframe and act upon the null values.因为 null 值不同,我想知道是否有一种方法可以读取同一 dataframe 中的两个 CSV 并根据 null 值进行操作。 For instance, because there are a lot more null values in the nsebank sheet, if I just read it into the same dataframe as nifty sheet and dropna, a lot of the nifty sheet data for those dates will be gone.例如,由于 nsebank 表中有更多的 null 值,如果我只是将其读入与漂亮的表格和 dropna 相同的 dataframe 中,那么这些日期的许多漂亮的表格数据将会消失。

For eg if I am to pull data out of AV or from any other data provider, cleaning up data for individual stocks is going to be tedious and slow.例如,如果我要从 AV 或任何其他数据提供商中提取数据,清理单个股票的数据将是乏味且缓慢的。

import pandas as pd
import numpy as np

bnf = pd.read_csv('nsebank.csv', index_col=0)
newbnf = bnf.dropna()

newbnf['Daily Returns'] = newbnf['Adj Close'].pct_change()

I simply concatenated the two excel sheets and did dropna().我只是连接了两个 excel 表并做了 dropna()。 See, if that works for you.看看,如果这对你有用。

df_nifty = pd.read_excel('Indexdata.xlsx', sheet_name= 'nifty')
df_bnf = pd.read_excel('Indexdata.xlsx', sheet_name= 'bnf')
df = pd.concat([df_nifty, df_bnf])
df.dropna(inplace = True)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM