pandas.read_csv易错用法

这篇博客介绍了如何使用Python的pandas库从CSV文件中读取数据,特别是处理带有特殊字符的文件路径,设置分隔符和列名。强调了在数据读取时设置header=None的重要性,以避免将第一行数据误认为列名。同时,提供了更多关于数据读取的资源链接供进一步学习。
data=pd.read_csv(r'B:\电子书\机器学习实战+源码\machinelearninginaction\Ch02\datingTestSet.txt',
                 sep='\t',names=['Flymiles','Videogames','Icecream','labels'])

文件路径前面一定要加个r,否则后面的反斜杠会被当成转义字符,加r代表后面是一个整体字符

import pegasus as pg import scanpy as sc import pandas as pd import matplotlib.colors as clr import matplotlib.pyplot as plt import matplotlib as mpl import numpy as np import seaborn as sns # Set a colormap colormap = clr.LinearSegmentedColormap.from_list('gene_cmap', ["#e0e0e1", '#4576b8', '#02024a'], N=200) # Aggregate the matrices pg.aggregate_matrices(csv_file = "/home/nealpsmith/projects/medoff/cellranger/aggregate_matrix.csv", what_to_return = "/home/nealpsmith/projects/medoff/data/all_data.h5sc") all_data = pg.read_input("/home/nealpsmith/projects/medoff/data/all_data.h5sc") pg.qc_metrics(all_data, percent_mito = 30) # Plot the percent mito/n genes # fig, ax = plt.subplots(1) # x = all_data.obs["n_genes"] # y = all_data.obs["percent_mito"] # _ = ax.hexbin(x, y, mincnt=1, xscale = "log") # _ = ax.set_xticks([10, 100, 1000]) # _ = ax.get_xaxis().set_major_formatter(mpl.ticker.ScalarFormatter()) # _ = ax.axvline(500, color="red") # _ = ax.axhline(30, color="red") # _ = plt.xlabel("Number of genes") # _ = plt.ylabel("percent mitochondrial UMIs") violin_dat = all_data.obs[["Channel", "percent_mito"]] violin_dat[["Channel"]] = [n.replace("ANA", "AC") for n in violin_dat["Channel"]] violin_dat[["Channel"]] = [n.replace("Pre", "Bln") for n in violin_dat["Channel"]] violin_order = ['500008_AC_Bln', '500008_AC_Dil', '500008_AC_Ag', '500012_AC_Bln', '500012_AC_Dil', '500012_AC_Ag', '500015_AC_Bln', '500015_AC_Ag', '500024_AC_Bln', '500024_AC_Dil', '500024_AC_Ag', '500021_AA_Bln', '500021_AA_Dil', '500021_AA_Ag', '500030_AA_Bln', '500030_AA_Dil', '500030_AA_Ag', '500032_AA_Bln', '500032_AA_Ag', '500035_AA_Bln', '500035_AA_Ag'] fig, ax = plt.subplots(1) sns.violinplot(x = "Channel", y = "percent_mito", color = "grey", data = violin_dat, inner = None, scale = "width", ax = ax, cut = 0, order = violin_order) for violin in ax.collections: violin.set_alpha(0.8) _ = ax.axhline(y = 30, color = "red", ls = "--") labs = ax.get_xticklabels() _ = ax.set_xticklabels(labs, rotation=90) _ = ax.set_ylabel("% mitochondrial UMIs") figure = plt.gcf() figure.set_size_inches(4, 3) figure.tight_layout() figure 我已经配置了python环境,我可以在Rstudio中运行这段代码吗
最新发布
09-29
signals fault_type \ B007_0.mat {'BA': [-0.013883012957765627, -0.058345327497... Ball B007_1.mat {'BA': [-0.02494944028144085, -0.0365378082339... Ball B007_2.mat {'BA': [0.07479378686435131, 0.079340611790167... Ball B007_3.mat {'BA': [0.009824349258423883, 0.02149319198839... Ball B014_0.mat {'BA': [0.024658354915196502, -0.0034675798029... Ball B014_1.mat {'BA': [-0.04822308552571353, -0.0373992279589... Ball B014_2.mat {'BA': [-0.017082634938750042, 0.0061343383550... Ball B014_3.mat {'BA': [-0.08045545964036006, -0.0205419878302... Ball B021_0.mat {'BA': [0.054796216401331546, -0.0256383236580... Ball B021_1.mat {'BA': [0.02298951819677145, 0.026007322351074... Ball B021_2.mat {'BA': [0.034492387292542885, 0.00664811429551... Ball B021_3.mat {'BA': [-0.007503571932946665, 0.0188116802925... Ball IR007_0.mat {'BA': [0.008146494935619943, 0.11119444745787... InnerRace IR007_1.mat {'BA': [-0.005919276734113309, 0.0306565096160... InnerRace IR007_2.mat {'BA': [0.020330740551127616, -0.0003512772530... InnerRace IR007_3.mat {'BA': [0.054478223463571444, 0.03258908399769... InnerRace IR014_0.mat {'BA': [-0.05292454985378002, 0.03865574688212... InnerRace IR014_1.mat {'BA': [-0.0861482948301088, -0.02168799809420... InnerRace IR014_2.mat {'BA': [-0.06199636215603381, -0.0293638399008... InnerRace IR014_3.mat {'BA': [0.08284138035922405, 0.083807077688600... InnerRace IR021_0.mat {'BA': [0.006875656043494057, 0.04288811895150... InnerRace IR021_1.mat {'BA': [0.04895917507340281, 0.089961074183195... InnerRace IR021_2.mat {'BA': [-0.01889112806743308, -0.0060956384531... InnerRace IR021_3.mat {'BA': [0.16660231413676066, 0.133688130160499... InnerRace OR007@12_0.mat {'BA': [0.03869577297627246, 0.009362716596450... OuterRace OR007@12_1.mat {'BA': [0.034129085550335024, 0.06326095498653... OuterRace OR007@12_2.mat {'BA': [-0.0664110399316921, -0.02351798355187... OuterRace OR007@12_3.mat {'BA': [0.0021856223057470214, 0.0019039605846... OuterRace OR007@3_0.mat {'BA': [-0.06365597903859956, 0.00374164707416... OuterRace OR007@3_1.mat {'BA': [-0.053526355173926565, 0.0258620127785... OuterRace OR007@3_2.mat {'BA': [-0.029154225821404027, 0.0286266643863... OuterRace OR007@3_3.mat {'BA': [-0.016014932178030284, -0.146947395086... OuterRace OR007@6_0.mat {'BA': [-0.02933921018593409, 0.01190411325620... OuterRace OR007@6_1.mat {'BA': [-0.0065979914343945, -0.00128665612282... OuterRace OR007@6_2.mat {'BA': [0.022881088037517625, -0.0418608704194... OuterRace OR007@6_3.mat {'BA': [-0.03527995538030922, -0.0760404301577... OuterRace OR014@6_0.mat {'BA': [-0.04434567049587477, 0.02606975977118... OuterRace OR014@6_1.mat {'BA': [0.02609576843170789, -0.02943182800746... OuterRace OR014@6_2.mat {'BA': [-0.021932136269107706, 0.0345209201107... OuterRace OR014@6_3.mat {'BA': [0.01514816552089373, 0.005571667004573... OuterRace OR021@12_0.mat {'BA': [-0.017401234116071314, 0.0192550270115... OuterRace OR021@12_1.mat {'BA': [-0.085321021645438, -0.045606718974814... OuterRace OR021@12_2.mat {'BA': [0.008722406199429086, -0.0064873267382... OuterRace OR021@12_3.mat {'BA': [-0.05841310398981675, 0.00419627286478... OuterRace OR021@3_0.mat {'BA': [-0.009852854645115348, 0.0284625558395... OuterRace OR021@3_1.mat {'BA': [-0.003914165176411444, -0.002223779419... OuterRace OR021@3_2.mat {'BA': [0.09011397011962469, 0.018795790099842... OuterRace OR021@3_3.mat {'BA': [-0.09694209571538906, -0.0518651422040... OuterRace OR021@6_0.mat {'BA': [-0.01227973749216366, -0.0720871954545... OuterRace OR021@6_1.mat {'BA': [0.02246363240705738, 0.011999339627631... OuterRace OR021@6_2.mat {'BA': [-0.1318167447446025, -0.09503073089692... OuterRace OR021@6_3.mat {'BA': [-0.05220006122745787, -0.0353766982205... OuterRace fault_code fault_size load rpm file_id has_BA has_DE \ B007_0.mat B 0.007 0 1796.0 X118 True True B007_1.mat B 0.007 1 1772.0 X119 True True B007_2.mat B 0.007 2 1748.0 X120 True True B007_3.mat B 0.007 3 1722.0 X121 True True B014_0.mat B 0.014 0 1796.0 X185 True True B014_1.mat B 0.014 1 1772.0 X186 True True B014_2.mat B 0.014 2 1749.0 X187 True True B014_3.mat B 0.014 3 1724.0 X188 True True B021_0.mat B 0.021 0 1796.0 X222 True True B021_1.mat B 0.021 1 1774.0 X223 True True B021_2.mat B 0.021 2 1754.0 X224 True True B021_3.mat B 0.021 3 1729.0 X225 True True IR007_0.mat IR 0.007 0 1797.0 X105 True True IR007_1.mat IR 0.007 1 1772.0 X106 True True IR007_2.mat IR 0.007 2 1748.0 X107 True True IR007_3.mat IR 0.007 3 1721.0 X108 True True IR014_0.mat IR 0.014 0 1796.0 X169 True True IR014_1.mat IR 0.014 1 1774.0 X170 True True IR014_2.mat IR 0.014 2 1752.0 X171 True True IR014_3.mat IR 0.014 3 1728.0 X172 True True IR021_0.mat IR 0.021 0 1797.0 X209 True True IR021_1.mat IR 0.021 1 1774.0 X210 True True IR021_2.mat IR 0.021 2 1752.0 X211 True True IR021_3.mat IR 0.021 3 1728.0 X212 True True OR007@12_0.mat OR 0.007 0 1797.0 X156 True True OR007@12_1.mat OR 0.007 1 1773.0 X158 True True OR007@12_2.mat OR 0.007 2 1750.0 X159 True True OR007@12_3.mat OR 0.007 3 1724.0 X160 True True OR007@3_0.mat OR 0.007 0 1797.0 X144 True True OR007@3_1.mat OR 0.007 1 1774.0 X145 True True OR007@3_2.mat OR 0.007 2 1751.0 X146 True True OR007@3_3.mat OR 0.007 3 1725.0 X147 True True OR007@6_0.mat OR 0.007 0 1796.0 X130 True True OR007@6_1.mat OR 0.007 1 1773.0 X131 True True OR007@6_2.mat OR 0.007 2 1750.0 X132 True True OR007@6_3.mat OR 0.007 3 1725.0 X133 True True OR014@6_0.mat OR 0.014 0 1796.0 X197 True True OR014@6_1.mat OR 0.014 1 1772.0 X198 True True OR014@6_2.mat OR 0.014 2 1749.0 X199 True True OR014@6_3.mat OR 0.014 3 1723.0 X200 True True OR021@12_0.mat OR 0.021 0 1796.0 X258 True True OR021@12_1.mat OR 0.021 1 1771.0 X259 True True OR021@12_2.mat OR 0.021 2 1746.0 X260 True True OR021@12_3.mat OR 0.021 3 1718.0 X261 True True OR021@3_0.mat OR 0.021 0 1796.0 X246 True True OR021@3_1.mat OR 0.021 1 1771.0 X247 True True OR021@3_2.mat OR 0.021 2 1747.0 X248 True True OR021@3_3.mat OR 0.021 3 1719.0 X249 True True OR021@6_0.mat OR 0.021 0 1796.0 X234 True True OR021@6_1.mat OR 0.021 1 1771.0 X235 True True OR021@6_2.mat OR 0.021 2 1748.0 X236 True True OR021@6_3.mat OR 0.021 3 1721.0 X237 True True has_FE B007_0.mat True B007_1.mat True B007_2.mat True B007_3.mat True B014_0.mat True B014_1.mat True B014_2.mat True B014_3.mat True B021_0.mat True B021_1.mat True B021_2.mat True B021_3.mat True IR007_0.mat True IR007_1.mat True IR007_2.mat True IR007_3.mat True IR014_0.mat True IR014_1.mat True IR014_2.mat True IR014_3.mat True IR021_0.mat True IR021_1.mat True IR021_2.mat True IR021_3.mat True OR007@12_0.mat True OR007@12_1.mat True OR007@12_2.mat True OR007@12_3.mat True OR007@3_0.mat True OR007@3_1.mat True OR007@3_2.mat True OR007@3_3.mat True OR007@6_0.mat True OR007@6_1.mat True OR007@6_2.mat True OR007@6_3.mat True OR014@6_0.mat True OR014@6_1.mat True OR014@6_2.mat True OR014@6_3.mat True OR021@12_0.mat True OR021@12_1.mat True OR021@12_2.mat True OR021@12_3.mat True OR021@3_0.mat True OR021@3_1.mat True OR021@3_2.mat True OR021@3_3.mat True OR021@6_0.mat True OR021@6_1.mat True OR021@6_2.mat True OR021@6_3.mat True读取数据完构建模型时出现了float() argument must be a string or a number, not 'dict'
09-24
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

@u@

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值