使用以下数据:
$cat date1.csv
Bob,2013-06-03T17:18:07
James,2013-06-03T17:18:07
Kevin,2013-06-03T17:18:07
$cat date2.csv
2012-12-02T18:30:31
2012-12-02T18:28:37
2013-06-01T12:16:05
Run Code Online (Sandbox Code Playgroud)
如何合并date1.csv和date2.csv文件?所需输出:
$cat merge-date1-date2.csv
Bob,2013-06-03T17:18:07,2012-12-02T18:30:31
James,2013-06-03T17:18:07,2012-12-02T18:28:37
Kevin,2013-06-03T17:18:07,2013-06-01T12:16:05
Run Code Online (Sandbox Code Playgroud)
请注意:最佳解决方案将能够快速管理大量的线路.
已在link1,link2,link3处针对基于文本的表情符号解决了此主题.但是,我想做一些与匹配简单表情符号略有不同的东西.我正在整理包含表情符号图标的推文.以下unicode信息仅包含此类表情符号:pdf.
使用带有英文单词的字符串,其中也包含pdf中的任何这些表情符号,我希望能够将表情符号的数量与单词数量进行比较.
我向前走的方向似乎不是最佳选择,我正在寻求一些帮助.正如您在下面的脚本中看到的那样,我只是计划从命令行完成工作:
$cat <file containing the strings with emoticons> | ./emo.py
Run Code Online (Sandbox Code Playgroud)
emo.py伪造脚本:
import re
import sys
for row in sys.stdin:
print row.decode('utf-8').encode("ascii","replace")
#insert regex to find the emoticons
if match:
#do some counting using .split(" ")
#print the counting
Run Code Online (Sandbox Code Playgroud)
我遇到的问题是解码/编码.我还没有找到一个如何编码/解码字符串的好选项,所以我可以正确找到图标.我想要搜索以查找单词和表情符号数量的字符串示例如下:
"笑脸图释岩!
我喜欢你
".
挑战:你能编写一个脚本来计算这个字符串中的单词和表情符号的数量吗?请注意,表情符号都位于单词旁边,两者之间没有空格.
试过这个:
import boto3
from boto3.s3.transfer import TransferConfig, S3Transfer
path = "/temp/"
fileName = "bigFile.gz" # this happens to be a 5.9 Gig file
client = boto3.client('s3', region)
config = TransferConfig(
multipart_threshold=4*1024, # number of bytes
max_concurrency=10,
num_download_attempts=10,
)
transfer = S3Transfer(client, config)
transfer.upload_file(path+fileName, 'bucket', 'key')
Run Code Online (Sandbox Code Playgroud)
结果:s3上的5.9 gig文件.似乎不包含多个部分.
我找到了这个例子,但part没有定义.
import boto3
bucket = 'bucket'
path = "/temp/"
fileName = "bigFile.gz"
key = 'key'
s3 = boto3.client('s3')
# Initiate the multipart upload and send the part(s)
mpu = …Run Code Online (Sandbox Code Playgroud) 使用以下数据框d:
day <- gl(8,1,24,labels=c("Mon","Tues","Wed","Thurs","Fri","Sat","Sun","Avg"))
day <- factor(day, level=c("Mon","Tues","Wed","Thurs","Fri","Sat","Sun","Avg"))
month<-gl(3,8,24,labels=c("Jan","Feb","Mar"))
month<-factor(month,level=c("Jan","Feb","Mar"))
snow<-gl(1,24,labels=c("Y"))
snow<-factor(snow,levels=c("Y","N"))
count <- c(4,5,6,8,3,4,9,5.57,2,4,3,7,1,9,3,4.14,7,9,6,3,1,2,8,5.14)
d <- data.frame(day=day,count=count,month=month,snow=snow)
Run Code Online (Sandbox Code Playgroud)
折线图背后的背景颜色与条形图相同:
ggplot(data=d[d$day=="Avg",], aes(x=day , y=count, fill=month)) +
geom_bar(position = "dodge", width = 1.2, stat="identity") +
geom_text(aes(label=month, x=day, y=count), position=position_dodge(width=1.2), vjust=-.6, size=3) +
geom_line(data=d[d$day!="Avg",], aes(x=day, y=count, group=month, colour=month)) +
facet_wrap(~snow,ncol=1,scales="free") +
scale_x_discrete(limits=levels(d$day))
Run Code Online (Sandbox Code Playgroud)
是否可以更改条形图后面部分的背景颜色?
可以cut在带¬分隔符的bash中使用吗?
这个问题是这里讨论的主题的扩展.对该链接的目标的一种解释是使用在人类文本中找不到(或很少发现)的分隔符.假设我们选择'Not Sign'(¬)作为分隔符.我的问题是关于使用cut所述分隔符来拉取文件的特定列.
例如,假设我们使用¬分隔符创建文件.文件prac.txt可能如下所示:
$cat prac.txt
"Billy""Car"¬"Red"¬"Garage"¬"3"
"Rob"¬"Truck"¬"Blue"¬"Street"¬"14"
Run Code Online (Sandbox Code Playgroud)
以下过程会产生错误:
$cut -d'¬' -f1 prac.txt
cut: the delimiter must be a single character
Try `cut --help' for more information.
Run Code Online (Sandbox Code Playgroud)
正确的输出是:
"Billy"
"Rob"
Run Code Online (Sandbox Code Playgroud)
来自python的可能有用的信息:
import unicodedata
>>>unicodedata.lookup('Not sign')
u'\xac'
Run Code Online (Sandbox Code Playgroud)
可能有用的字符转换链接.
我的猜测是该-d标志使用了一些我尚未尝试过的"¬"表示,否则它仅适用于单个ascii字符.在此先感谢您的帮助.
我正在努力为每个直方图设置xlim并创建1列图形,以便x轴刻度对齐.作为新的大熊猫,我不确定如何应用答案适用:使用熊猫覆盖多个直方图.
>import from pandas import DataFrame, read_csv
>import matplotlib.pyplot as plt
>import pandas as pd
>df=DataFrame({'score0':[0.047771,0.044174,0.044169,0.042892,0.036862,0.036684,0.036451,0.035530,0.034657,0.033666],
'score1':[0.061010,0.054999,0.048395,0.048327,0.047784,0.047387,0.045950,0.045707,0.043294,0.042243]})
>print df
score0 score1
0 0.047771 0.061010
1 0.044174 0.054999
2 0.044169 0.048395
3 0.042892 0.048327
4 0.036862 0.047784
5 0.036684 0.047387
6 0.036451 0.045950
7 0.035530 0.045707
8 0.034657 0.043294
9 0.033666 0.042243
>df.hist()
>plt.xlim(-1.0,1.0)
Run Code Online (Sandbox Code Playgroud)
结果只将x轴上的一个边界设置为[-1,1].
我非常熟悉R中的ggplot,只是在python中尝试pandas/matplotlib.我愿意接受更好的策划思路的建议.任何帮助将不胜感激.

更新#1(@ ct-zhu):
我尝试了以下内容,但子图上的xlim编辑似乎并未在新的x轴值上转换bin宽度.因此,图形现在具有奇数的bin宽度,并且仍然具有多列图形:
for array in df.hist(bins=10):
for subplot in array:
subplot.set_xlim((-1,1))
Run Code Online (Sandbox Code Playgroud)

更新#2:
越接近使用layout,但箱的宽度不等于间隔长度除以箱数.在下面的例子中,我设置了bins=10.因此,每个箱子在[-1,1]间隔的宽度应为2/10=0.20 …
使用以下数据:
$cat p1.csv
R,3
R,4
S,1
S,2
S,3
R,2
T,4
R,3
ST,4
RST,2
RSTR,4
Run Code Online (Sandbox Code Playgroud)
首先根据第2列进行排序:
$cat p1.csv | sort -t "," -k2
S,1
R,2
RST,2
S,2
R,3
R,3
S,3
R,4
RSTR,4
ST,4
T,4
Run Code Online (Sandbox Code Playgroud)
我想计算第二列的1,2,3和4的数量.有点像$ cat p1.csv | sort -t"," - k2 | uniq -f2 -c .....可以将uniq应用于一列吗?-f2未正确将uniq应用于正确的字段.输出应该采用第二列中唯一值的第一个实例并计算它们的数量.因此,必须首先在第二列上对数据进行排序.正确的输出看起来像:
1 S,1
3 R,2
3 R,3
4 R,4
Run Code Online (Sandbox Code Playgroud)
建议?
使用以下数据框:
sdf<-data.frame(hours=gl(n=3,k=1,length=9,labels=c(0,2,4)),
count=c(4500,1500,2600,4000,800,200,1500,50,20),
machine=gl(n=3,k=3,length=9,labels=c("A","B","C")))
Run Code Online (Sandbox Code Playgroud)
可以使用以下任一脚本生成以下图表:
ggplot(data=sdf,aes(x=hours,y=count,group=machine,fill=machine))+
geom_area(data=sdf[sdf$machine=="A",])+
geom_area(data=sdf[sdf$machine=="B",])+
geom_area(data=sdf[sdf$machine=="C",])
ggplot(data=sdf,aes(x=hours,y=count,group=machine,fill=machine))+
geom_area(position="dodge")
Run Code Online (Sandbox Code Playgroud)

但是,当填充颜色更改时,图例中的项目将消失.
ggplot(data=sdf,aes(x=hours,y=count,group=machine,fill=machine))+
geom_area(data=sdf[sdf$machine=="A",])+
geom_area(data=sdf[sdf$machine=="B",],fill="darkorchid")+
geom_area(data=sdf[sdf$machine=="C",])
Run Code Online (Sandbox Code Playgroud)

理想情况下,图例应显示颜色变化.
问题:什么脚本可以在图例中创建项目以及为这些项目提供颜色控制?
另一个线程有一个与我类似的问题,但遗漏了可重现的代码。
有问题的脚本的目标是创建一个尽可能具有内存效率的进程。所以我尝试编写一个类corpus()来利用 gensims 的功能。但是,我遇到了一个 IndexError,我不确定在创建lda = models.ldamodel.LdaModel(corpus_tfidf, id2word=checker.dictionary, num_topics=int(options.number_of_topics)).
我使用的文档与 gensim 教程中使用的文档相同,我将其放入 tutorial_example.txt:
$ cat tutorial_example.txt
Human machine interface for lab abc computer applications
A survey of user opinion of computer system response time
The EPS user interface management system
System and human system engineering testing of EPS
Relation of user perceived response time to error measurement
The generation of random binary unordered trees
The intersection graph of paths in trees
Graph minors IV Widths …Run Code Online (Sandbox Code Playgroud) 使用p.txt:
$cat p.txt
R 3
R 4
S 1
S 2
R 1
T 1
R 3
Run Code Online (Sandbox Code Playgroud)
以下命令根据第二列进行排序:
$cat p.txt | sort -k2
R 1
S 1
T 1
S 2
R 3
R 3
R 4
Run Code Online (Sandbox Code Playgroud)
以下命令删除第二列中的重复值:
$cat p.txt | sort -k2 | awk '!x[$2]++'
R 1
S 2
R 3
R 4
Run Code Online (Sandbox Code Playgroud)
现在为 sapce 插入一个逗号,我们有以下文件:
$cat p1.csv
R,3
R,4
S,1
S,2
R,1
T,1
R,3
Run Code Online (Sandbox Code Playgroud)
以下命令仍然根据第二列进行排序:
$cat p1.csv | sort -t "," -k2
R,1
S,1
T,1
S,2
R,3
R,3 …Run Code Online (Sandbox Code Playgroud) 为什么这个系列中的值会None转换为True和False?
环境:
进口:
from IPython.display import display
import pandas as pd
Run Code Online (Sandbox Code Playgroud)
转换None为True:
df_test1 = pd.DataFrame({'test_column':[0,1,None]})
df_test1['test_column'] = df_test1.test_column.astype(bool)
display(df_test1)
Run Code Online (Sandbox Code Playgroud)
转换None为False:
df_test2 = pd.DataFrame({'test_column':[0,1,None,'test']})
df_test2['test_column'] = df_test2.test_column.astype(bool)
display(df_test2)
Run Code Online (Sandbox Code Playgroud)
这是预期的行为吗?