amdforlive

u/amdforlive


r/learnpython•

I have a dataframe like this :

​

Namelast name
JohnDonald
Tom Petter

I want to select all the row with Name is NaN, then apply lambda function to get a string from last name to replace the NaN value.

I have try:

df.loc[df['Name'].isnull() ] = df.loc[df['Name'].isnull()].apply( lambda x  : (x['last name'].split(' ')[0]) ,axis=1)
                                                                                               

But it return error : Must have equal len keys and value when setting with an iterable

00

r/learnpython•

I am doing something like the following :

Testing['new_value'] = Testing.apply(lambda x  : convert(x['value']),axis=1)

I am using a lambda function to create a new column. And pandas remind me to I should Try using .loc[row_indexer,col_indexer] = value instead

​

How should I code to avoid this reminder ?

01

r/learnpython•

I am working on a scrapy project. I want to know how to pass a argument to a spider class.

I want to pass the keyword argument (file_path='C:\\') to the dictionary variable in my spider class.

I try the following two methods but didn't work.

Method 1:

class MySpider(scrapy.Spider):
    name = 'MySpider'

    custom_settings = { 'FEED_URI': self.file_path }

Method 2:

class MySpider(scrapy.Spider):
    name = 'MySpider'

    def __init__(self, file_path ='', **kwargs):
        custom_settings = {
            'FEED_URI' :  file_path + '.json'
        }
        super(MySpider,self).__init__(**kwargs)

​

I have read the [https

14



r/learnpython•

I want to build a program to to compare the similarity of a input phrase with a array of short phrases.

And find the most similar one.

Should I start from extract the keyword from the input first then compare with the array ?

One of the characteristic of the input and data array is all of them are noun phrases like animal name, household item and place name etc. Would it help me to exploit ?

11

r/learnpython•

I have a csv tabular data around 3M rows, in following structure:

​

rowColumn 1
1[978]
2[2341]
3234
4213
523
3000000023

Some of the raw data are corrupted. Like the first two row which have a number store in list type in which I am only interest to the number inside. All I want is to extract the number 978 , 2341 out of the square brackets. The whole column are read as object to dataframe initially, and now I want to extract the number and cast whole column back to number.

I have try to use a for loop with condition to convert the item one by one but it is very slow.

Is there any more efficient method ?

28

r/learnpython•

I have a 3gb DB in mongodb. But, I am not quite familiar with the javascript like query in mongo, so I loaded the Dateset to pandas dataframe. It takes endlessly.

So how should I speed up the process? or any other solutions rather than mongodb should I use ?

11




r/sysadmin•

I find that a code like the following in the creation page of instances.

POST https://www.googleapis.com/compute/v1/projects/helpful316/zones/us-central1-a/instances
{
  "kind": "compute#instance",
  "name": "instance-1",
  "zone": "projects/helpful-wa",
  "machineType": "projects/helpful-6/zones/us-central1-a/machineTypes/n1-standard-1",
  "displayDevice": {
    "enableDisplay": false
  },
  "metadata": {
    "kind": "compute#metadata",
    "items": []
  },
  "tags": {
}

I am not familar with the linux and api. Is the above code used to create instances ?

I know how to write request in python so can I use the above code to

01

r/mongodb•

I very new to mongodb. I have used mongodb to store some data which have text and image local path. I hope to find a simple gui which can display the data in table view and have some simple sorting function.

217